This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Module | |
| def delegate(*methods, to:) | |
| methods.each do |method_name| | |
| define_method(method_name) do |*args| | |
| to.send(method_name, *args) | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Director | |
| attr_reader :training_team, :fellows | |
| delegate :train_new_fellow, :train_new_fellow, to: training_team | |
| delegate :size, :[], :<<, to: fellows | |
| def initialize | |
| @training_team = TrainingTeam.new | |
| @fellows = [] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Router | |
| [:get, :post, :put, :patch, :delete].each do |method_name| | |
| define_method(method_name) do | |
| "This is a #{method_name} method" | |
| end | |
| end | |
| end | |
| router = Router.new | |
| router.get #=> "This is a get method" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| attr_accessor :name | |
| def book_reading | |
| "Elixir Cookbook" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person = Class.new do | |
| attr_accessor :name | |
| def book_reading | |
| "Elixir Cookbook" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Book = "Eloquent Ruby" | |
| Module.const_get(:Book) #=> "Eloquent Ruby" | |
| Module.const_set(:Book, "Ruby Science") #=> "Ruby Science" | |
| Module.const_get(:Book) #=> "Ruby Science" | |
| class Person | |
| def name | |
| "Sword Master" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Module | |
| def const_missing(constant) | |
| "Constant #{constant} is really missing" | |
| end | |
| end | |
| class House | |
| end | |
| Module.const_get(:House) #=> House |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| def initialize(n) | |
| @name = n | |
| end | |
| def issues | |
| family = "No Money" | |
| relationship = "Complex" | |
| friends = "No Friends" | |
| binding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| def name | |
| "Name is Aboki" | |
| end | |
| alias_method :aboki_name, :name | |
| def name | |
| "Ikem Okonkwo" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| def name | |
| @name || "person" | |
| end | |
| def name=(val) | |
| return if val == "person" | |
| @name = val | |
| end | |
| end |