lib/bioinform/support/callable_symbol.rb in bioinform-0.1.1 vs lib/bioinform/support/callable_symbol.rb in bioinform-0.1.2

- old
+ new

@@ -1,16 +1,14 @@ -require 'bioinform/support/curry_except_self' - # Useful extension for &:symbol - syntax to make it possible to pass arguments for method in block # ['abc','','','def','ghi'].tap(&:delete.('')) # ==> ['abc','def','ghi'] # [1,2,3].map(&:to_s.(2)) # ==> ['1','10','11'] # ['abc','cdef','xy','z','wwww'].select(&:size.() == 4) # ==> ['cdef', 'wwww'] # ['abc','aaA','AaA','z'].count(&:upcase.().succ == 'AAB') # ==> 2 # [%w{1 2 3 4 5},%w{6 7 8 9}].map(&:join.().length) # ==> [5,4] class Symbol def call(*args, &block) - obj=BasicObject.new.instance_exec(self,args,block) do |meth,params,block| + obj = BasicObject.new.instance_exec(self,args,block) do |meth,params,block| @postprocess_meth = [meth] @postprocess_args = [params] @postprocess_block = [block] self end @@ -35,6 +33,18 @@ method_missing(:==, other) end obj end -end +end + + +=begin +# Much simplier but ['abc','cdef','xy','z','wwww'].select(&:size.() == 4) wouldn't work +class Symbol + def call(*args, &block) + proc do |recv| + recv.__send__(self, *args, &block) + end + end +end +=end \ No newline at end of file