Sha256: 027107eb448af1d8dc4455b9e5cd1fed9e32d2009d84ec2b48c95300c98f2193

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

class Ryan::Func
  attr_accessor :sexp, :_private

  alias private? _private

  def initialize(sexp, _private)
    @sexp, @_private = sexp, _private
  end

  def conditions
    @conditions ||= Ryan::SexpDecorator.new(sexp).each_sexp_condition.map &Ryan::Condition.method(:new)
  end

  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

  def find_assignments(s_expression)
    s_expression.find_nodes(:op_asgn_or) + s_expression.find_nodes(:iasgn)
  end

  # @note we drop(1) to get rid of :args (which should be the first item in the sexp)
  # @note called from subclasses
  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ryan-1.2.1 lib/ryan/func.rb
ryan-1.2.0 lib/ryan/func.rb
ryan-1.1.0 lib/ryan/func.rb
ryan-1.0.0 lib/ryan/func.rb