Class: Scmd::StoredCommands

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

Defined Under Namespace

Classes: Stub

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStoredCommands

Returns a new instance of StoredCommands.



9
10
11
# File 'lib/scmd/stored_commands.rb', line 9

def initialize
  @hash = Hash.new{ |h, k| h[k] = Stub.new(k) }
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



7
8
9
# File 'lib/scmd/stored_commands.rb', line 7

def hash
  @hash
end

Instance Method Details

#==(other_stored_commands) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/scmd/stored_commands.rb', line 33

def ==(other_stored_commands)
  if other_stored_commands.kind_of?(StoredCommands)
    self.hash == other_stored_commands.hash
  else
    super
  end
end

#add(cmd_str, &block) ⇒ Object



13
14
15
# File 'lib/scmd/stored_commands.rb', line 13

def add(cmd_str, &block)
  @hash[cmd_str].tap{ |s| s.set_default_proc(&block) }
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/scmd/stored_commands.rb', line 29

def empty?
  @hash.empty?
end

#get(cmd_str, opts = nil) ⇒ Object



17
18
19
# File 'lib/scmd/stored_commands.rb', line 17

def get(cmd_str, opts = nil)
  @hash[cmd_str].call(opts)
end

#remove(cmd_str) ⇒ Object



21
22
23
# File 'lib/scmd/stored_commands.rb', line 21

def remove(cmd_str)
  @hash.delete(cmd_str)
end

#remove_allObject



25
26
27
# File 'lib/scmd/stored_commands.rb', line 25

def remove_all
  @hash.clear
end