Module: LiveAST::Common
- Included in:
- Evaler
- Defined in:
- lib/live_ast/common.rb
Class Method Summary collapse
- .arg_to_str(arg) ⇒ Object
- .check_arity(args, range) ⇒ Object
- .check_is_binding(obj) ⇒ Object
- .location_for_eval(*args) ⇒ Object
Class Method Details
.arg_to_str(arg) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/live_ast/common.rb', line 6 def arg_to_str(arg) begin arg.to_str rescue NameError thing = if arg.nil? then nil else arg.class end raise TypeError, RUBY_VERSION < "2.0.0" ? "can't convert #{thing.inspect} into String" : "no implicit conversion of #{thing.inspect} into String" end end |
.check_arity(args, range) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/live_ast/common.rb', line 19 def check_arity(args, range) unless range.include? args.size range = 0 if range == (0..0) raise ArgumentError, "wrong number of arguments (#{args.size} for #{range})" end end |
.check_is_binding(obj) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/live_ast/common.rb', line 28 def check_is_binding(obj) unless obj.is_a? Binding raise TypeError, RUBY_VERSION < "2.1.0" ? "wrong argument type #{obj.class} (expected Binding)" : "wrong argument type #{obj.class} (expected binding)" end end |
.location_for_eval(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/live_ast/common.rb', line 37 def location_for_eval(*args) bind, *location = args if bind case location.size when 0 NATIVE_EVAL.call("[__FILE__, __LINE__]", bind) when 1 [location.first, 1] else location end else ["(eval)", 1] end end |