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 |
# File 'lib/live_ast/common.rb', line 6 def arg_to_str(arg) arg.to_str rescue NameError thing = arg.nil? ? nil : arg.class = "no implicit conversion of #{thing.inspect} into String" raise TypeError, end |
.check_arity(args, range) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/live_ast/common.rb', line 15 def check_arity(args, range) return if range.include? args.size range = 0 if range == (0..0) = "wrong number of arguments (given #{args.size}, expected #{range})" raise ArgumentError, end |
.check_is_binding(obj) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/live_ast/common.rb', line 24 def check_is_binding(obj) return if obj.is_a? Binding = "wrong argument type #{obj.class} (expected binding)" raise TypeError, end |
.location_for_eval(*args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/live_ast/common.rb', line 31 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 |