Class: ConsoleBuddy::Augment::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/console_buddy/augment.rb

Defined Under Namespace

Classes: InvalidTypeError

Instance Method Summary collapse

Instance Method Details

#method(klass, method_name, type: :instance, &block) ⇒ Object

Raises:



30
31
32
33
34
# File 'lib/console_buddy/augment.rb', line 30

def method(klass, method_name, type: :instance, &block)
  raise InvalidTypeError, "Invalid method type. Must be either :instance or :class" unless %i[instance class].include?(type)

  store(klass) <<  { method_name: method_name, block: block, method_type: type }
end

#method_alias(klass, method_name, new_method_name, type: :instance) ⇒ Object

Raises:



36
37
38
39
40
41
# File 'lib/console_buddy/augment.rb', line 36

def method_alias(klass, method_name, new_method_name, type: :instance)
  raise InvalidTypeError, "Invalid method type. Must be either :instance or :class" unless %i[instance class].include?(type)

  block = ::Proc.new { |*args| send(method_name, *args) }
  store(klass) <<  { method_name: new_method_name, block: block, method_type: type }
end