lib/rubyvis/javascript_behaviour.rb in rubyvis-0.1.5 vs lib/rubyvis/javascript_behaviour.rb in rubyvis-0.1.6

- old
+ new

@@ -1,17 +1,19 @@ class TrueClass + # Return 1 def to_i 1 end end class FalseClass + # Return 0 def to_i 0 end end - +# :stopdoc: unless Object.public_method_defined? :instance_exec class Object module InstanceExecHelper; end include InstanceExecHelper def instance_exec(*args, &block) # :nodoc: @@ -29,20 +31,30 @@ InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil end ret end end - end +# :startdoc: + # Add javascript-like +apply+ and +call+ methods to Proc, # called +js_apply+ and +js_call+, respectivly. - class Proc - attr_accessor :order - # Apply on javascript is very flexible. Can accept more or less - # variables than explicitly defined parameters on lambda, so the method - # adds or remove elements according to lambda arity + # Used on Rubyvis::Nest + attr_accessor :order # :nodoc: + + # Emulation of +apply+ javascript method. + # +apply+ has this signature + # my_proc.apply(my_obj, args) + # where + # [+my_proc+] a proc + # [+my_obj+] object inside proc is eval'ed + # [args] array of arguments for proc + # + # +apply+ on javascript is very flexible. Can accept more or less + # variables than explicitly defined parameters on lambda, so this + # method adds or remove elements according to lambda arity # def js_apply(obj,args) arguments=args.dup # Modify numbers of args to works with arity min_args=self.arity>0 ? self.arity : (-self.arity)-1 @@ -57,9 +69,9 @@ else obj.instance_exec(*arguments,&self) end end # Same as js_apply, but using explicit arguments - def js_call(obj,*args) + def js_call(obj, *args) js_apply(obj,args) end end