Class: SafeHash::SafeNil

Inherits:
BlankSlate
  • Object
show all
Includes:
Singleton
Defined in:
lib/rails_ext/micelaneous/safe_hash.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



80
81
82
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 80

def method_missing m, *args
  self[m, *args]
end

Instance Method Details

#[](key, *args) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 70

def [] key, *args
  if key.to_s.last == '!'
    raise "No key #{key}"
  elsif args.empty?
    SafeNil.instance
  else
    return *args
  end
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 84

def include? key
  false
end

#inspectObject



100
101
102
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 100

def inspect
  nil.inspect
end

#to_bObject



88
89
90
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 88

def to_b
  false
end

#to_hObject



96
97
98
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 96

def to_h
  {}
end

#to_yaml(*args) ⇒ Object



92
93
94
# File 'lib/rails_ext/micelaneous/safe_hash.rb', line 92

def to_yaml *args
  nil.to_yaml *args
end