Sha256: 04fe0402046db59f6695033e4e511b5f957efc81310fe584dff9c9be4fc42737
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
def compile_ruby_methods(input_file_contents) # These are some interesting methods that we really miss in Javascript. # So we have made these methods available method_map_replacement = { ".split" => ".split(\" \")", ".join" => ".join()", ".strip" => ".replace(/^\\s+|\\s+$/g,'')", ".lstrip" => ".replace(/^\\s+/g,\"\")", ".rstrip" => ".replace(/\\s+$/g,\"\")", ".to_s" => ".toString()", ".reverse" => ".reverse()", ".empty?" => ".length == 0", ".upcase" => ".toUpperCase()", ".downcase" => ".toLowerCase()", } method_map = method_map_replacement.keys method_map_regex = method_map.collect {|name| name.gsub(".","\\.")} method_map_regex = Regexp.new(method_map_regex.join("|")) modified_file_contents = input_file_contents.clone input_file_contents.each_with_index do |line, index| if line.match(method_map_regex) method_match = line.match(method_map_regex).to_a[0] unless line.include?(method_match + "(") line = line.sub(method_match,method_map_replacement[method_match]) end end modified_file_contents[index] = line end return modified_file_contents end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nilac-0.0.4.3.9.4 | lib/nilac/compile_ruby_methods.rb |
nilac-0.0.4.3.9.3 | lib/nilac/compile_ruby_methods.rb |