Permalink
Browse files

remove to_proc on string

is unused, and causes issues when using ruleby with rails. closes #19
  • Loading branch information...
1 parent acb2f44 commit 989717e5671e90335127fb54a6d0a49a925328b5 @cwoodcox cwoodcox committed Nov 13, 2011
Showing with 0 additions and 37 deletions.
  1. +0 −37 lib/ruleby.rb
View
37 lib/ruleby.rb
@@ -19,41 +19,4 @@ def engine(name, &block)
yield e if block_given?
return e
end
-end
-
-class String
- unless ''.respond_to?(:to_proc)
- def to_proc &block
- params = []
- expr = self
- sections = expr.split(/\s*->\s*/m)
- if sections.length > 1 then
- eval sections.reverse!.inject { |e, p| "(Proc.new { |#{p.split(/\s/).join(', ')}| #{e} })" }, block && block.binding
- elsif expr.match(/\b_\b/)
- eval "Proc.new { |_| #{expr} }", block && block.binding
- else
- leftSection = expr.match(/^\s*(?:[+*\/%&|\^\.=<>\[]|!=)/m)
- rightSection = expr.match(/[+\-*\/%&|\^\.=<>!]\s*$/m)
- if leftSection || rightSection then
- if (leftSection) then
- params.push('$left')
- expr = '$left' + expr
- end
- if (rightSection) then
- params.push('$right')
- expr = expr + '$right'
- end
- else
- self.gsub(
- /(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*:|self|arguments|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/, ''
- ).scan(
- /([a-z_$][a-z_$\d]*)/i
- ) do |v|
- params.push(v) unless params.include?(v)
- end
- end
- eval "Proc.new { |#{params.join(', ')}| #{expr} }", block && block.binding
- end
- end
- end
end

0 comments on commit 989717e

Please sign in to comment.