Sha256: 7393fe0f4959b0d5946a969baa57f2956b69d1a5c9d59821be862bf60a2f7dfb
Contents?: true
Size: 917 Bytes
Versions: 19
Compression:
Stored size: 917 Bytes
Contents
require 'facets/more/functor' # # class X # # this.y = "Hello" # # this.up = lambda { puts @y.upcase } # # end # # X.new.up #=> HELLO # class Module def this klass = self Functor.new do |op, *args| case op.to_s[-1,1] when '=' op = op.to_s.chomp('=') if Proc === args[0] define_method( op, &args[0] ) else define_method( op ) do r = instance_variable_set( "@#{op}", args[0] ) klass.class.class_eval %{ def #{op}; @#{op}; end } r end end else klass.class_eval %{ def #{op}; @#{op}; end } end end end end =begin test require 'test/unit' class TCthis < Test::Unit::TestCase class Foo this.bar = 10 end def test01 x = Foo.new assert_equal( 10, x.bar ) end end =end
Version data entries
19 entries across 19 versions & 1 rubygems