This file contains 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
eval("5 + 10") #=> 15 | |
eval("def name; 'Ikem Okonkwo'; end;") # creates a method called name | |
name #=> "Ikem Okonkwo" calls the method created by eval |
This file contains 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 | |
c = %q{def company; "Andela"; end} | |
instance_eval(c) | |
def initialize | |
@name = "Ikem Okonkwo" | |
end | |
def make | |
instance_eval("def name; 'Ikem Okonkwo'; end") |
This file contains 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 | |
name = %q{def name; "Ikem Okonkwo"; end} | |
class_eval(name) | |
end | |
Person.name #=> undefined method error | |
Person.new.name #=> "Ikem Okonkwo" |
This file contains 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 | |
@@name = "codesword" | |
end | |
Person.class_variable_get(:@@name) #=> "codesword" | |
Person.class_variable_set(:@@name, "Ikem") | |
Person.class_variable_get(:@@name) #=> "Ikem" | |
Person.new.class_variable_get("@@name") #=> undefined method |
This file contains 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 | |
@book = "Harry Porter" | |
def initialize | |
@book = "The Rails Way" | |
end | |
end | |
Person.instance_variable_get(:@book) #=> "Harry Porter" | |
Person.new.instance_variable_get(:@book) #=> "The Rails Way" |
This file contains 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 | |
def train_new_fellow(fellow) | |
puts "Will DO" | |
end | |
end |
This file contains 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 TrainingTeam | |
def train_new_fellow(name) | |
# Trains all new fellow | |
end | |
def completed_initial_training | |
# Returns fellows that has completed training | |
end | |
end |
This file contains 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 TrainingTeam | |
def train_new_fellow(name) | |
# Trains all new fellow | |
end | |
def training_period(fellow_name) | |
# Returns the period the fellow has been in training | |
end | |
end |
This file contains 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
require 'forwardable' | |
class Director | |
attr_reader :training_team, :fellows | |
def_delegator :training_team, :train_new_fellow, :train_new_fellow | |
def initialize | |
@training_team = TrainingTeam.new | |
end | |
end |
This file contains 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 RubyTrainingTeam | |
def train_new_fellow(name) | |
# Trains all new fellow in ruby track | |
end | |
end | |
class PythonTrainingTeam | |
def train_new_fellow(name) | |
# Trains all new fellowin python track | |
end |
OlderNewer