Class: Brash::CommandContext

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth = 0) ⇒ CommandContext

Returns a new instance of CommandContext.



14
15
16
# File 'lib/brash.rb', line 14

def initialize(depth=0)
  @depth = depth
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



11
12
13
# File 'lib/brash.rb', line 11

def method_missing(method, *args, &block)
  @command = Command.new(method, *args, &block).tap{|c| c.context = self}
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



10
11
12
# File 'lib/brash.rb', line 10

def command
  @command
end

#depthObject (readonly)

Returns the value of attribute depth.



10
11
12
# File 'lib/brash.rb', line 10

def depth
  @depth
end

Class Method Details

.surround(*args, &block) ⇒ Object



17
18
19
20
21
# File 'lib/brash.rb', line 17

def self.surround(*args, &block)
  context = CommandContext.new(*args)
  context.instance_eval(&block) if block_given?
  context
end