Module: EmanLib
- Defined in:
- lib/emanlib.rb,
lib/patch/let.rb,
lib/patch/enum.rb,
lib/patch/lambda.rb
Defined Under Namespace
Modules: Enum Classes: Lambda, Maplet
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.let(*args, &block) ⇒ Object
A convenient shorthand for ‘Maplet.new.define!(…)`.
-
.support_lambda ⇒ Object
Support for using a
_as the second operand with operators.
Class Method Details
.let(*args, &block) ⇒ Object
A convenient shorthand for ‘Maplet.new.define!(…)`.
116 117 118 |
# File 'lib/patch/let.rb', line 116 def let(*args, &block) Maplet.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`
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/patch/lambda.rb', line 165 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 |