Module: EmanLib
- Defined in:
- lib/emanlib.rb,
lib/patch/enum.rb
Defined Under Namespace
Modules: Enum
Class Method Summary collapse
-
.let(*args, &block) ⇒ Object
Helper method to create definitions.
-
.support_lambda ⇒ Object
Support for using a ‘_` as the second operand with operators.
Class Method Details
.let(*args, &block) ⇒ Object
Helper method to create definitions. A convenient shorthand for ‘Object.new.define(…)`.
47 48 49 |
# File 'lib/emanlib.rb', line 47 def let(*args, &block) Object.new.define(*args, &block) end |
.support_lambda ⇒ Object
Support for using a ‘_` as the second operand with operators. WARN: This method WILL MODIFY the standard library classes. In particular, the operators: `- * / % ** & | ^ << >> <=> == === != > < >= <=` in the classes: `Integer, Float, Rational, Complex, Array, String, Hash, Range, Set`
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/emanlib.rb', line 55 def support_lambda [[Integer, Float, Rational, Complex, Array, String, Hash, Range, Set], %i[- * / % ** & | ^ << >> <=> == === != > < >= <=]].op(:product) .each do |klass, op| next unless klass.instance_methods(false).include?(op) original = klass.instance_method(op) klass.define_method(op) do |other| if other.is_a?(Lambda) repr = [self] repr.concat(other.repr) repr << Lambda::Function.new(op) Lambda.new(repr) else original.bind(self).call(other) end end end end |