Module: PriceHubble::Utils::Bangers
- Extended by:
- ActiveSupport::Concern
- Included in:
- BaseEntity, BaseEntity, Client::Base
- Defined in:
- lib/price_hubble/utils/bangers.rb
Overview
Generate bang variants of methods which use the Decision
flow control.
Class Method Summary collapse
-
.bangers(*methods) ⇒ Object
Generate bang variants for the given methods.
Class Method Details
.bangers(*methods) ⇒ Object
Generate bang variants for the given methods. Be sure to use the bangers
class method AFTER all method definitions, otherwise it will raise errors about missing methods.
rubocop:disable Metrics/MethodLength because the method template
is better inlined
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/price_hubble/utils/bangers.rb', line 20 def bangers(*methods) methods.each do |meth| raise NoMethodError, "#{self}##{meth} does not exit" \ unless instance_methods(false).include? meth if instance_method(meth).arity.zero? raise ArgumentError, "#{self}##{meth} does not accept arguments" end class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{meth}!(*args, **kwargs, &block) #{meth}(*args, **kwargs, bang: true, &block) end RUBY end end |