Class: Ryan::Func
- Inherits:
-
Object
- Object
- Ryan::Func
- Defined in:
- lib/ryan/func.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_private ⇒ Object
(also: #private?)
Returns the value of attribute _private.
-
#sexp ⇒ Object
Returns the value of attribute sexp.
Instance Method Summary collapse
- #assignments ⇒ Object
- #conditions ⇒ Object
- #find_assignments(s_expression) ⇒ Object
-
#initialize(sexp, _private) ⇒ Func
constructor
A new instance of Func.
- #map_args(_sexp = sexp, list = []) ⇒ Object
Constructor Details
#initialize(sexp, _private) ⇒ Func
Returns a new instance of Func.
6 7 8 |
# File 'lib/ryan/func.rb', line 6 def initialize(sexp, _private) @sexp, @_private = sexp, _private end |
Instance Attribute Details
#_private ⇒ Object Also known as: private?
Returns the value of attribute _private.
2 3 4 |
# File 'lib/ryan/func.rb', line 2 def _private @_private end |
#sexp ⇒ Object
Returns the value of attribute sexp.
2 3 4 |
# File 'lib/ryan/func.rb', line 2 def sexp @sexp end |
Instance Method Details
#assignments ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ryan/func.rb', line 14 def assignments nodes = find_assignments(sexp) sexp.find_nodes(:rescue).each do |node| node = node[1] if node[1].first == :block nodes.concat find_assignments(node) end nodes.map &Ryan::Assignment.method(:new) end |
#conditions ⇒ Object
10 11 12 |
# File 'lib/ryan/func.rb', line 10 def conditions @conditions ||= Ryan::SexpDecorator.new(sexp).each_sexp_condition.map &Ryan::Condition.method(:new) end |
#find_assignments(s_expression) ⇒ Object
23 24 25 |
# File 'lib/ryan/func.rb', line 23 def find_assignments(s_expression) s_expression.find_nodes(:op_asgn_or) + s_expression.find_nodes(:iasgn) end |
#map_args(_sexp = sexp, list = []) ⇒ Object
Note:
we drop(1) to get rid of :args (which should be the first item in the sexp)
Note:
called from subclasses
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ryan/func.rb', line 29 def map_args(_sexp = sexp, list = []) val = _sexp.first return list.drop(1) unless val case val when Symbol map_args(_sexp.drop(1), list << val) when Sexp map_args(_sexp.drop(1), list << val[1]) else nil end end |