lib/surrogate/hatchling.rb in surrogate-0.6.0 vs lib/surrogate/hatchling.rb in surrogate-0.6.1
- old
+ new
@@ -23,10 +23,11 @@
interfaces_must_match! method_name, args
Value.factory(get_ivar method_name).value(method_name)
end
def prepare_method(method_name, args, &block)
+ must_know method_name
set_ivar method_name, Value.factory(*args, &block)
end
def invocations(method_name)
invoked_methods[method_name]
@@ -73,14 +74,38 @@
def unset_ivar(method_name)
instance.__send__ :remove_instance_variable, ivar_for(method_name)
end
def ivar_for(method_name)
- case method_name
- when /\?$/
- "@#{method_name.to_s.chop}_p"
- else
- "@#{method_name}"
+ method_name = method_name.to_s
+ if method_name.end_with? ?? then "@#{method_name.to_s.chop}_p"
+ elsif method_name.end_with? ?! then "@#{method_name.to_s.chop}_b"
+ elsif method_name == '[]' then '@_brackets'
+ elsif method_name == '**' then '@_splat_splat'
+ elsif method_name == '!@' then '@_ubang'
+ elsif method_name == '+@' then '@_uplus'
+ elsif method_name == '-@' then '@_uminus'
+ elsif method_name == ?* then '@_splat'
+ elsif method_name == ?/ then '@_divide'
+ elsif method_name == ?% then '@_percent'
+ elsif method_name == ?+ then '@_plus'
+ elsif method_name == ?- then '@_minus'
+ elsif method_name == '>>' then '@_shift_right'
+ elsif method_name == '<<' then '@_shift_left'
+ elsif method_name == ?& then '@_ampersand'
+ elsif method_name == ?^ then '@_caret'
+ elsif method_name == ?| then '@_bang'
+ elsif method_name == '<=' then '@_less_eq'
+ elsif method_name == ?< then '@_less'
+ elsif method_name == ?> then '@_greater'
+ elsif method_name == '>=' then '@_greater_eq'
+ elsif method_name == '<=>' then '@_spaceship'
+ elsif method_name == '==' then '@_2eq'
+ elsif method_name == '===' then '@_3eq'
+ elsif method_name == '!=' then '@_not_eq'
+ elsif method_name == '=~' then '@_eq_tilde'
+ elsif method_name == '!~' then '@_bang_tilde'
+ else "@#{method_name}"
end
end
end
end