Class: Hash

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

Overview

Hashの値をドット表記で取得可能とするための、Hashクラスに独自のメソッド定義を行う

Examples:

次のような形でHashの値を取得することができる

foo[:bar] => "baz"
foo.bar => "baz"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



31
32
33
34
35
# File 'lib/NIFTY.rb', line 31

def method_missing(meth, *args, &block)
  if args.size == 0
    self[meth.to_s] || self[meth.to_sym]
  end
end

Instance Method Details

#does_not_have?(key) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/NIFTY.rb', line 45

def does_not_have?(key)
  self[key].nil? || self[key].to_s.empty?
end

#has?(key) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/NIFTY.rb', line 41

def has?(key)
  self[key] && !self[key].to_s.empty?
end

#typeObject



37
38
39
# File 'lib/NIFTY.rb', line 37

def type
  self['type']
end