Skip to content

Instantly share code, notes, and snippets.

@codesword
Created June 5, 2016 12:28
Show Gist options
  • Save codesword/8936e147681e5f0187a23262cc8cc223 to your computer and use it in GitHub Desktop.
Save codesword/8936e147681e5f0187a23262cc8cc223 to your computer and use it in GitHub Desktop.
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
end
person_class = Module.const_get(:Person) #=> Person
p = person_class.new
p.name #=> "Sword Master"
Module.const_set(:Trainer, Class.new { attr_accessor :stack })
trainer_class = Module.const_get(:Trainer) #=> Trainer
trainer = trainer_class.new
trainer.stack = "Ruby"
trainer.stack #=> "Ruby"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment