Class: Rattler::Parsers::ActionCode

Inherits:
Object
  • Object
show all
Defined in:
lib/rattler/parsers/action_code.rb

Direct Known Subclasses

AssertCode, DisallowCode, EffectCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ ActionCode

:nodoc:



14
15
16
17
18
19
20
21
22
# File 'lib/rattler/parsers/action_code.rb', line 14

def initialize(code)
  if md = /\A\s*\|([^|]*)\|(.*)\Z/.match(code)
    @param_names = md[1].split(',').map {|_| _.strip }
    @body = md[2].strip
  else
    @param_names = []
    @body = code.strip
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



24
25
26
# File 'lib/rattler/parsers/action_code.rb', line 24

def body
  @body
end

#param_namesObject (readonly)

Returns the value of attribute param_names.



24
25
26
# File 'lib/rattler/parsers/action_code.rb', line 24

def param_names
  @param_names
end

Instance Method Details

#arg_bindings(args) ⇒ Object



34
35
36
37
38
39
# File 'lib/rattler/parsers/action_code.rb', line 34

def arg_bindings(args)
  if param_names.count > args.count
    raise ArgumentError, 'more parameter names than arguments'
  end
  to_bindings param_names.zip(args)
end

#bind(scope, bind_args) ⇒ Object



26
27
28
# File 'lib/rattler/parsers/action_code.rb', line 26

def bind(scope, bind_args)
  bind_in body, scope, bind_args
end

#scoped_bindings(scope, bind_args) ⇒ Object



30
31
32
# File 'lib/rattler/parsers/action_code.rb', line 30

def scoped_bindings(scope, bind_args)
  to_bindings(scope).merge(arg_bindings(bind_args))
end