Skip to content

Instantly share code, notes, and snippets.

@clemens
Created March 27, 2017 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clemens/e4d01d78b7f407be8cc78544fe9fafb8 to your computer and use it in GitHub Desktop.
Save clemens/e4d01d78b7f407be8cc78544fe9fafb8 to your computer and use it in GitHub Desktop.
module Trailblazer; end
module My; end
class Trailblazer::Operation
def self.inherited(klass)
*mod_names, klass_name = klass.name.split('::')
mod = const_get(mod_names.join('::'))
mod.define_singleton_method(klass_name) do |*args|
klass.new.call(*args)
end
end
end
class My::Operation < Trailblazer::Operation
def call(attributes = {})
puts attributes.inspect
end
end
My::Operation(first_name: 'foo', last_name: 'bar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment