Sha256: 2ee26db036e450697d712dbf87913ef5bba2d596a886176bb935a6cb07472d26
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
# $Id: 1st.rb, v0.2 2004/08/21 transami Exp $ =begin rdoc = 1st Class Methods Easy access to method as objects. And they retain state! === Example def hello puts "Hello World!" end p method(:hello) #=> <Method: #hello> == Comments I think the best solution would be using the notation <tt>::ameth</tt>. This would require some minor changes to Ruby, but with few backward incompatabilites if parantheticals revert back to the actual method invocation. Although this later stipulation means capitalized methods would not be accessible in this way b/c they would intefere with constant lookup. It's a trade off. # Current Proposed Alternative Foo.Bar() # method call method call method call Foo.Bar # method call method call method call Foo.bar() # method call method call method call Foo.bar # method call method call method call Foo::Bar() # method call method call 1st class method Foo::Bar # constant lookup constant lookup constant lookup Foo::bar() # method call method call 1st class method Foo::bar # method call 1st class method 1st class method Then again this dosen't address bound versus unbound. Which do you prefer? == Legal Ruby License Copyright (c) 2004 Thomas Sawyer =end class Object alias_method :method_pre1st, :method def method(s) ( @__methods__ ||= {} )[s] ||= method_pre1st(s) end end # not needed #class Module # alias_method :instance_method_pre1st, :instance_method # def instance_method(s) # ( @__instance_methods__ ||= {} )[s] ||= instance_method_pre1st(s) # end #end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
carats-0.3.0 | lib/carat/1st.rb |