1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
def is_rbx?
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
end
def jruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
end
module M
def hello; :hello_module; end
end
$o = Object.new
def $o.hello; :hello_singleton; end
# A comment for hello
# It spans two lines and is indented by 2 spaces
def hello; :hello; end
# a
# b
def comment_test1; end
# a
# b
def comment_test2; end
# a
#
# b
def comment_test3; end
# a
# b
def comment_test4; end
# a
# b
# c
# d
def comment_test5; end
# This is a comment for MyLambda
MyLambda = lambda { :lambda }
MyProc = Proc.new { :proc }
name = "name"
M.instance_eval <<-METHOD, __FILE__, __LINE__ + 1
def hello_#{name}(*args)
send_mesg(:#{name}, *args)
end
METHOD
M.class_eval <<-METHOD, __FILE__, __LINE__ + 1
def hello_#{name}(*args)
send_mesg(:#{name}, *args)
end
METHOD
# module_eval to DRY code up
#
M.module_eval <<-METHOD, __FILE__, __LINE__ + 1
# module_eval is used here
#
def hi_#{name}
@var = #{name}
end
METHOD
# case where 2 methods are defined inside an _eval block
#
M.instance_eval <<EOF, __FILE__, __LINE__ + 1
def #{name}_one()
if 43
44
end
end
def #{name}_two()
if 44
45
end
end
EOF
# class_eval without filename and lineno + 1 parameter
M.class_eval "def #{name}_three; @tempfile.#{name}; end"
|