Created
July 30, 2014 15:39
-
-
Save hiyosi/2b04e1e4907be17207c6 to your computer and use it in GitHub Desktop.
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 Hoge | |
def self.hoge | |
obj = Kernel.const_get(klass.capitalize).new | |
attributes.each do |key| | |
obj.send("#{key}=", key.to_s + "!!!") | |
end | |
p obj | |
end | |
def self.klass | |
end | |
def self.attributes | |
end | |
end | |
Foo = Class.new(Hoge) do | |
attr_accessor :name, :email | |
def self.klass | |
self.name | |
end | |
def self.attributes | |
[:name, :email] | |
end | |
end | |
Bar = Class.new(Hoge) do | |
attr_accessor :id, :pass | |
def self.klass | |
self.name | |
end | |
def self.attributes | |
[:id, :pass] | |
end | |
end | |
Foo.hoge | |
Bar.hoge | |
# % ruby sample.rb | |
# #<Foo:0x007f871190b858 @name="name!!!", @email="email!!!"> | |
# #<Bar:0x007f871190b498 @id="id!!!", @pass="pass!!!"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment