Sha256: 95a035361a7b05a086e6f15221d9f2f0bad09a3ef009d5853fdd65db5d058b86
Contents?: true
Size: 1.01 KB
Versions: 4
Compression:
Stored size: 1.01 KB
Contents
module Cucumber class ArgCountError < StandardError end module CoreExt # Proc extension that allows a proc to be called in the context of any object. # Also makes it possible to tack a name onto a Proc. module CallIn attr_accessor :name def call_in(obj, *args) obj.extend(mod) a = arity == -1 ? 0 : arity if self != Tree::Step::PENDING && args.length != a # We have to manually raise when the block has arity -1 (no pipes) raise ArgCountError.new("wrong number of arguments (#{args.length} for 0)") else obj.__send__(meth, *args) end end def arity2 arity == -1 ? 0 : arity end def backtrace_line to_s.match(/[\d\w]+@(.*)>/)[1] + ":in `#{name}'" end def meth @meth ||= "__cucumber_#{object_id}" end def mod p = self m = meth @mod ||= Module.new do define_method(m, &p) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems