Sha256: 18cc513457fe74ab988da88f1d7f7650cb801c52c4407bb578a90cfc3945a78a
Contents?: true
Size: 1.12 KB
Versions: 10
Compression:
Stored size: 1.12 KB
Contents
# TODO Is there any good way to avoid 'unless const_defined?'. module Kernel unless const_defined?("OPERATORS") OPERATORS = %w{ +@ -@ + - ** * / % ~ <=> << >> < > === == =~ <= >= | & ^ []= [] } OPERATORS_REGEXP = Regexp.new( '(' << OPERATORS.collect{ |k| Regexp.escape(k) }.join('|') << ')' ) OPERATORS_ESC_TABLE = { "+@" => "op_plus_self", "-@" => "op_minus_self", "+" => "op_plus", "-" => "op_minus", "**" => "op_pow", "*" => "op_mul", "/" => "op_div", "%" => "op_mod", "~" => "op_tilde", "<=>" => "op_cmp", "<<" => "op_lshift", ">>" => "op_rshift", "<" => "op_lt", ">" => "op_gt", "===" => "op_case_eq", "==" => "op_equal", "=~" => "op_apply", "<=" => "op_lt_eq", ">=" => "op_gt_eq", "|" => "op_or", "&" => "op_and", "^" => "op_xor", "[]=" => "op_store", "[]" => "op_fetch" } end def op_esc( str ) str.gsub(OPERATORS_REGEXP){ OPERATORS_ESC_TABLE[$1] } end end
Version data entries
10 entries across 10 versions & 1 rubygems