Class: AsReadonly::Hash

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

Overview

Be aware that #[] and #default are not blacklisted here but they can change the internal state of Hash if default proc is implemented to change the Hash itself:

h = Hash.new {|h,k| h = k*k }

Constant Summary collapse

REMOVED =
%w|
     []= clear default= default_proc=
     delete delete_if replace  keep_if
     merge! update rehash reject!
     select! shift store
|.each do |method|
  undef_method(method)
end

Instance Method Summary collapse

Methods inherited from Hash

#as_readonly

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*params) ⇒ Object

Raises:

  • (NoMethodError)


19
20
21
# File 'lib/as_readonly/hash.rb', line 19

def method_missing(*params)
  raise NoMethodError
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/as_readonly/hash.rb', line 23

def respond_to?(method, include_private = false)
  return false if REMOVED.include?(method.to_s)
  super
end