Class: Y2R::AST::YCP::Compare
- Defined in:
- lib/y2r/ast/ycp.rb
Constant Summary collapse
- OPS_TO_OPS =
{ "==" => "==", "!=" => "!=" }
- OPS_TO_METHODS =
{ "<" => "less_than", ">" => "greater_than", "<=" => "less_or_equal", ">=" => "greater_or_equal" }
Instance Method Summary collapse
Methods inherited from Node
#always_returns?, #compile_as_copy_if_needed, #compile_statements, #compile_statements_inside_block, #compile_statements_with_whitespace, #creates_local_scope?, #needs_copy?, #never_nil?, #optimize_last_statement, #optimize_next, #optimize_return, #remove_duplicate_imports, transfers_comments
Instance Method Details
#compile(context) ⇒ Object
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 |
# File 'lib/y2r/ast/ycp.rb', line 1062 def compile(context) if OPS_TO_OPS[op] Ruby::BinaryOperator.new( :op => OPS_TO_OPS[op], :lhs => lhs.compile(context), :rhs => rhs.compile(context) ) elsif OPS_TO_METHODS[op] Ruby::MethodCall.new( :receiver => Ruby::Variable.new(:name => "Ops"), :name => OPS_TO_METHODS[op], :args => [lhs.compile(context), rhs.compile(context)], :block => nil, :parens => true ) else raise "Unknown compare operator #{op}." end end |