module Fn

Constants

VERSION

Public Instance Methods

Fn(prc = nil, *rargs, &blk) click to toggle source

Function pseudo-constructor

Like Symbol#to_proc

Fn(:upcase).call('xxx') #=> 'XXX'

But the resulting Fn can take extra args besides ‘self`

Fn(:ljust).call('xxx', 5) #=> '  XXX'

Can be used to coerce/convert an existing Proc (compare Integer(), Array())

Fn(->{ |x| x.length }).call('xxx') #=> 3

Or called with a block directly

Fn { |x| x.length }.call('xxx') #=> 3
# File lib/fn.rb, line 101
def Fn(prc = nil, *rargs, &blk)
  if Symbol === prc
    Fn { |*args| args.first.send(prc, *rargs, *args.drop(1)) }
  else
    Fn.new(&(prc || blk))
  end
end
Also aliased as: fn
fn(prc = nil, *rargs, &blk)
Alias for: Fn