Skip to content

Instantly share code, notes, and snippets.

eval("5 + 10") #=> 15
eval("def name; 'Ikem Okonkwo'; end;") # creates a method called name
name #=> "Ikem Okonkwo" calls the method created by eval
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")
class Person
name = %q{def name; "Ikem Okonkwo"; end}
class_eval(name)
end
Person.name #=> undefined method error
Person.new.name #=> "Ikem Okonkwo"
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
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"
class Director
def train_new_fellow(fellow)
puts "Will DO"
end
end
class TrainingTeam
def train_new_fellow(name)
# Trains all new fellow
end
def completed_initial_training
# Returns fellows that has completed training
end
end
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
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
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