# -*- coding: utf-8 -*- module Yaks module Util extend self extend Forwardable def_delegators Inflection, :singular, :singularize, :pluralize def underscore(str) str.gsub(/::/, '/') .gsub(/(? 0 context.instance_eval(&maybe_proc) else # In case it's a lambda with zero arity instance_eval fails context.instance_exec(&maybe_proc) end else maybe_proc.() end else maybe_proc end end def curry_method(name) method(name).to_proc.curry end alias μ curry_method def identity_function ->(x) {x} end alias ι identity_function def juxt(*procs) ->(*args) { procs.map &σ(:call, *args) } end def curry_symbol(symbol, *args, &blk) ->(obj) { obj.method(symbol).to_proc.curry.(*args, &blk) } end alias σ curry_symbol alias send_with_args curry_symbol def extract_options(args) if args.last.is_a? Hash [args.take(args.count-1), args.last] else [args, {}] end end end end