Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created December 2, 2011 05:50
Show Gist options
  • Select an option

  • Save pasberth/1421965 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1421965 to your computer and use it in GitHub Desktop.
謎的なおぶじぇくと
def object constant=nil, &defi
obj = ->() do
b = binding
return ->(exp) do
b.eval exp
end
end.call
->() do
if constant.respond_to? :to_sym
if [Class, Module].include? self.class
klass = self
else
klass = self.class
end
klass.const_set constant.to_sym, obj
end
end.call
obj
end
object :MyObj
MyObj.call "member = 'hello'"
puts MyObj.call "member" # hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment