Module: Cucumber::CoreExt::CallIn
- Defined in:
- lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb
Overview
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.
Constant Summary collapse
- PROC_PATTERN =
/[\d\w]+@(.*):(.*)>/
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #arity2 ⇒ Object
- #call_in(obj, *args) ⇒ Object
- #file_colon_line ⇒ Object
- #meth ⇒ Object
- #mod ⇒ Object
- #to_backtrace_line ⇒ Object
- #to_comment_line ⇒ Object
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
40 41 42 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 40 def name @name end |
Instance Method Details
#arity2 ⇒ Object
52 53 54 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 52 def arity2 arity == -1 ? 0 : arity end |
#call_in(obj, *args) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 42 def call_in(obj, *args) obj.extend(mod) if self != StepMother::PENDING && args.length != arity2 # We have to manually raise when the block has arity -1 (no pipes) raise ArityMismatchError.new("expected #{arity2} block argument(s), got #{args.length}") else obj.__send__(meth, *args) end end |
#file_colon_line ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 20 def file_colon_line path, line = *to_s.match(PROC_PATTERN)[1..2] path = File.(path) pwd = Dir.pwd path = path[pwd.length+1..-1] "#{path}:#{line}" end |
#meth ⇒ Object
56 57 58 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 56 def meth @meth ||= "__cucumber_#{object_id}" end |
#mod ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 60 def mod p = self m = meth @mod ||= Module.new do define_method(m, &p) end end |
#to_backtrace_line ⇒ Object
12 13 14 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 12 def to_backtrace_line "#{file_colon_line}:in `#{name}'" end |
#to_comment_line ⇒ Object
16 17 18 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 16 def to_comment_line "# #{file_colon_line}" end |