Ultimate Ruby Metaprogramming Course

Learn metaprogramming and write better & more elegant ruby code using Ruby language's metaprogramming features.
5.0 (3 ratings) Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
45 students enrolled
$200
Take This Course
  • Lectures 39
  • Contents Video: 4.5 hours
    Other: 30 mins
  • Skill Level All Levels
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 5/2015 English

Course Description

Ever thought that ruby metaprogramming is reserved for experienced ruby gurus? Well, not anymore!

Almost all ruby developers want to learn metaprogramming. But, approaching the subject might feel a bit intimidating. Because, every time you tried, all available material was referring to even more complicated or less known concepts. Such as: eigenclasses, ruby object model, classes being objects themselves, etc.

Several years ago, I spent several months researching about ruby metaprogramming and synthesising all available material. At the end, it turned out to be very simple to grasp and understand. The only problem is that there was no one resource that put all moving parts of the subject together and the result is this Ruby Metaprogramming course.

This video course will teach you ruby metaprogramming by introducing small, simple and less known ruby insights in each video. And once you learn them, metaprogramming will just start to make sense.

At the end of the course, you will:

  • Understand Ruby Metaprogramming and join the "Ruby Metaprogramming Gurus" club.
  • Better understand the Ruby language. Since, metaprogramming is in integral part of the laguage.
  • Write more efficient and elegant ruby code using language's metaprogramming features.
  • Be able to understand and explain the magic behind the code/syntax in all popular gems.
  • and of course write your own DSL's for your domains (just like rspec, rake, etc.).

Course overview

Metaprogramming is such an integral part of the Ruby language, that in order to learn it, you need to understand the specific language features. This features are less known and usually ruby books don't explain them. But, once you are introduced to them, metaprogramming will start to make sense. That's why, the course's main content will start by introducing several Ruby insights.

In the next section of the course, you will learn about methods that are involved in metaprogramming. Along the way, we will go through several examples that demystifies magic behind most popular gem syntaxes.

In the last section of the course, we will put together everything you learned into practice and build together our own rspec, domain specific language and some of the rails most popular magical methods.

What are the requirements?

  • Basic knowledge of Ruby.
  • Ruby environment to run your code.

What am I going to get from this course?

  • Understand all the magic of the language and Rails.
  • Write better, more elegant and efficient ruby code.
  • Join the "Ruby Guru" pride.
  • Write own DSL, gems, etc.

What is the target audience?

  • Ruby developers who are familiar with the ruby language basics, syntax, etc.
  • Rails developers who want to improve their code and write more efficient code.
  • This course is probably not for you, if you are new to Ruby and want to learn the Ruby programming language basics.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Intoduction
05:06

Welcome lecture. Here you will learn who this course is for and what you will learn.

Article

This lecture gives you an overview of the course layout, its structure and birds eye view agenda. Also, you will find contact details for your feedback or more individual one-on-one help.

  • Skype for one-on-one sessions.
  • Personal email address for other queries.
Section 2: Ruby Insights
03:09

This insight shows that everything is an object in ruby. Numbers, booleans, even top level scope is run within an object.

Many other insights, that we will cover, are only possible because of this feature of ruby language. That's why, it is very important that you remember this feature of ruby.

07:26
This lecture covers 3 insights:
  • Open Classes
  • Ruby is a duck typed language
  • Class definitions are runnable code
First two are broadly known features of ruby, but the third one is more interesting insight about the ruby classes.
Article

The key to any learning is to make sure that you retain newly acquired information. And the best way to guarantee high retention is to do material revision.

In this revision lecture, you will be reminded about the key points from the 2 previous video lectures and also get some more nuances that I did not cover. I will do this by demonstrating an example code. So, you need to analyse the code and make your own conclusions. This step is also key for deep learning.

Lectures 2, 3 and 4
5 questions
12:57

In this lecture you will learn that classes in ruby are objects themselves. This is the key insight that you need to understand about the ruby classes. The whole ruby metaprogramming is only possible because of this feature of ruby classes.

You will learn that your class names are just constants, and your classes are just an instances of "Class" class from standard ruby library.

Article

The key to any learning is to make sure that you retain newly acquired information. And the best way to guarantee high retention is to do material revision.

In this revision lecture, you will be reminded about the key points from the "Classes are objects" video and also get some more nuances that I did not cover. I will do this by demonstrating some example code. So, take your time and analyse the code and make your own conclusions about it. This step is key for deep learning.

13:36

This insight talks about scopes. You will learn when, how, why and to what scopes are changed in your ruby code.

Also, you will be given a simple rule that explains all possible scope changes. Remember the rule and you will always know the value of current "self".

Article

The key to any learning is to make sure that you retain newly acquired information. And the best way to guarantee high retention is to do material revision.

In this revision lecture, you will be reminded about the key points from the "Scopes" video and also get some more nuances that I did not cover in the video. I will do this by demonstrating some example code. So, take your time and analyse the code and make your own conclusions about it. This step is key for deep learning.

Classes are objects & Scopes
10 questions
14:50

This insight shows that classes and modules in ruby are essentially the same with the only difference being that you can initialise and build inheritance hierarchies with classes, but not modules.

Article

The key to any learning is to make sure that you retain newly acquired information. And the best way to guarantee high retention is to do material revision.

In this revision lecture, you will be reminded about the key points from the "Classes are modules with hierarchy" video and also get some more nuances that I did not cover in the video. I will do this by demonstrating some example code. So, take your time and analyse the code and make your own conclusions about it. This step is key for deep learning.

11:51

In this video, you will learn all about inheritance in ruby. How classes' inheritance is built and how included modules fit into the picture (in what order, etc.).

Article

The key to any learning is to make sure that you retain newly acquired information. And the best way to guarantee high retention is to do material revision.

In this revision lecture, you will be reminded about the key points from the "Inheritance hierarchy" video and also get some more nuances that I did not cover in the video. I will do this by demonstrating some example code. So, take your time and analyse the code and make your own conclusions about it. This step is key for deep learning.

5 questions

Please note, that the purpose of the quizzes in this course is to help you assess yourself on how well you understood covered material, and help me to draw your attention to some specific aspects of the subject at hand. You are not marked or compared to any other student. Everything in this course is here with the only one purpose: help you learn Ruby Metaprogramming!

11:12

Unlike other programming languages, ruby classes don't have class properties. They just spring into existence when they are assigned a value. In this video, you will try to understand and visualise where instance variables and methods reside.

Understanding it will help you better understand why your code can or cannot access an instance variable or a method. Also, it will be of great help to understand ruby method lookup rules.

Article

Quick revision for "Where variables and methods live?" video lecture.

09:46

This insight shows and explains which exact method definition ruby will call when you send a message to an object. You will be given a list of 4 simple and easy to remember directives, that ruby uses to find a method.

Knowing which exact method will be executed is the key to doing metaprogramming. You will need to know exactly where you should dynamically add a method to achieve your goal. So, make sure you pay special attention during this lecture.

Article

Quick revision for "Method lookup" video lecture. In this revision, we will apply the insight from previous revision lecture and drastically simplify the method lookup rule.

10:38

This insight is all about variables and variable scope changes in ruby language. You will learn all about the following variable scopes:

  • global variables
  • class variables
  • instance variables
  • local variables
  • constants

You will also learn about each variable lifeline. When a variables is created and when is it removed/unset.

07:58

In this lecture, you will put everything you've learned so far into a grand picture, that is known as "Ruby Object Model".

I tried to make this lecture more visual with code examples that starts with a simple code and incrementally builds into more complex structure that shows different aspects of ruby object model. Also, everything will be visualized to help you grasp the ideas and concepts more easily.

09:03

In this lecture, I will point out some aspects of blocks in Ruby that you need to know to use their full potential in your metaprogramming practice. Along the way, you will demystify one of the common tricks used in Ruby on Rails (&:symbol) and understand how/why it works.

Section 3: Metaprogrammer's Toolkit
14:39

In this video, you will learn about methods from ruby standard library that get information about your objects. For example, object class, name, defined public, private, protected, instance, singleton methods, etc. Also, about available variables, their values and how to change their values.

05:17

In this video you will learn one of your first metaprogramming tricks. You will learn how to create/imitate custom language keywords like "require", "raise", "puts" or ActiveRecord's "validates" methods.

19:44

In this video, we will continue to go through methods from Standard Ruby Library that are used in metaprogramming. We've already learned about the methods that help us get information about classes, methods and variables. So, it is about time to learn how to create them.

04:20

In this video, you will learn how you can create your own method that behaves just like built-in "attr_accessor" method. Also, you will learn that this technique can be used to create methods from Rails. Such as: "validates", "belongs_to", "attr_accessible", etc. from ActiveRecord classes. This will completely demystify the magic behind these Rails' methods.

10:16

You've learned about creating and getting information about classes, methods and all kinds of variables. Now, it time to learn what methods Ruby standard library provides in order to change existing code. You will learn all methods that help you change your classes, methods and variables.

05:56

In this video, we will build our own method that behaves just like "alias_method_chain" method from Rails. This will help you demystify the magic behind and help you write your own similar methods for your own projects.

07:30

So, you've learned all about methods that let you create, change and remove classes, methods and variables. Learning how to run any code in different scope increases your possibilities by many fold. So, in this video, you will do just that! You will learn about different methods that Ruby has to offer.

09:40

It's really handy to be able to intercept and hook into the changes that happen in your classes and modules. You can add some custom behavior or validations when a module is included within another class for example.

This is a really simple concept, but only highly dynamic language such as Ruby could have functionality like this.

15:02

If you have developed for Rails, you should have used its' "ActiveSupport::Concern" helper module. In this video, you will build your own "ActiveSupport::Concern" helper module. If you don't want to include the whole "ActiveSupport" gem into your project just for this feature, you will be able to always write your own.

11:12

I will go through the "ActiveSupport::Concern" module code from Rails and explain how it is implemented. This demo will give you an idea of how all the methods you've learned in this section work together to achieve some requirement.

Section 4: Practice and Excersises
Article

`.tap` method was introduced in Ruby 1.9. But, you can create it yourself using the methods that we've covered. This tasks explains the `.tap` method and defines the exercise.

05:11

In this video I demonstrate and walk you through the process of writing .tap() method and further improving it.

Article

This task introduces some features of "Struct" class from the Standard Ruby Library and asks you implement them.

11:10

In this video, you will see an implementation of `Struct` class. We will build `ConStruct` class together (pun intended) that duplicates features of the `Struct` class from the Standard Ruby Library.

Article

This task requires you to create a custom DSL for generating HTML code. Just like many popular ruby gems (eg. arbre).

17:00

In this video, I show a solution to previous task. You will learn how can you write a code that is combined with the Ruby language's syntax imitates a custom DSL.

05:12

In this video we will look into the ways how we can run code in isolated scopes or "blank slate" environment.

10:59

You will learn how to create shared scopes between different methods or classes that no one else can access.

Article

In this lecture, we will go through many "magical" code in Rails' source code and consider different ways they can be implemented. Also, you will learn the reasons behind why those "tricks" work.

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Said Abduvaliev, Experienced Software Engineer

Said Abduvaliev is a an experienced full stack web developer with over 10 years experience. In the last 5 years, he has been involved in several successful startups built on Ruby on Rails. Latest involved projects: KupiKupon, BeSmarty, LocalOne, etc. (12M page views/day).

Said has experience writing enterprise systems using Java, PHP and Ruby. He has worked for and involved in project for United Nations Development Programme, Ministry of Economy, Tax Committee and others. He has always been a passionate teacher. Currently, he gives lectures at the University of Westminster.

Also, he enjoys front-end development. He writes his thoughts on JavaScript and jQuery in his popular "jQuery HowTo" blog.

Ready to start learning?
Take This Course