@anonymous/MonumentalStylishOlingo
Ruby

No description

repl talk
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module BlackMagic
  def self.included(klass)
    klass.extend(MethodAccessorMacros)
  end
  
  module MethodAccessorMacros
    def method_accessor(method_name)
      self.class.instance_eval do
        Array(method_name).each do
          define_method("#{method_name}_fn".intern) do
            method(method_name.intern)
          end
        end
      end
    end
  end
end

module Foo
  include BlackMagic

  method_accessor :bar

  def self.bar(x)
    if x == "lorem"
      "bar"
    else
      "baz"
    end
  end
end

xs = ["lorem", "ipsum", "dolor"]

xs.map(&Foo::bar_fn)
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]