-
-
Save vzvu3k6k/ce32d270ca5cc8cd7077 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 = method(__method__).receiver.new | |
attributes.each do |key| | |
obj.send("#{key}=", key.to_s + "!!!") | |
end | |
p obj | |
end | |
def self.attributes | |
end | |
end | |
Foo = Class.new(Hoge) do | |
attr_accessor :name, :email | |
def self.attributes | |
[:name, :email] | |
end | |
end | |
Bar = Class.new(Hoge) do | |
attr_accessor :id, :pass | |
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
method(__method__).receiver
がHoge
にならないのは意外。