Class: RubyLabs::ElizaLab::Dictionary

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

Overview

Dictionary

A Dictionary object is basically a Hash, but it overrides [] and []= to be case-insensitive.

Instance Method Summary collapse

Constructor Details

#initializeDictionary

Create a new empty dictionary.



313
314
315
316
# File 'lib/elizalab.rb', line 313

def initialize
  super
  @lc_keys = Hash.new
end

Instance Method Details

#[](x) ⇒ Object

Look up word x in the dictionary, after converting all the letters in x to lower case.



320
321
322
# File 'lib/elizalab.rb', line 320

def [](x)
  @lc_keys[x.downcase]
end

#[]=(x, y) ⇒ Object

Convert all letters in x to lower case, then save item y with the converted key.



326
327
328
329
# File 'lib/elizalab.rb', line 326

def []=(x,y)
  super
  @lc_keys[x.downcase] = y
end

#has_key?(x) ⇒ Boolean

Convert x to lower case, then see if there is an entry for the converted key in the dictionary.

Returns:

  • (Boolean)


333
334
335
# File 'lib/elizalab.rb', line 333

def has_key?(x)
  return @lc_keys.has_key?(x.downcase)
end