Class: HashyObject
- Inherits:
-
Object
- Object
- HashyObject
- Defined in:
- lib/hashy_object.rb,
lib/hashy_object/version.rb
Defined Under Namespace
Classes: TooMuchRecursionException
Constant Summary collapse
- MAX_RECURSION_LEVELS =
100
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#obj ⇒ Object
Returns the value of attribute obj.
-
#recursion_level ⇒ Object
Returns the value of attribute recursion_level.
Instance Method Summary collapse
-
#initialize(obj, recursion_level = 0) ⇒ HashyObject
constructor
A new instance of HashyObject.
- #inspect ⇒ Object
- #inspectable? ⇒ Boolean
- #inspectify ⇒ Object
Constructor Details
#initialize(obj, recursion_level = 0) ⇒ HashyObject
Returns a new instance of HashyObject.
11 12 13 14 15 |
# File 'lib/hashy_object.rb', line 11 def initialize(obj, recursion_level = 0) raise TooMuchRecursionException if recursion_level > MAX_RECURSION_LEVELS self.obj = obj self.recursion_level = recursion_level end |
Instance Attribute Details
#obj ⇒ Object
Returns the value of attribute obj.
8 9 10 |
# File 'lib/hashy_object.rb', line 8 def obj @obj end |
#recursion_level ⇒ Object
Returns the value of attribute recursion_level.
9 10 11 |
# File 'lib/hashy_object.rb', line 9 def recursion_level @recursion_level end |
Instance Method Details
#inspect ⇒ Object
17 18 19 20 21 |
# File 'lib/hashy_object.rb', line 17 def inspect return obj if obj.is_a?(String) return obj.inspect if inspectable? inspectify end |
#inspectable? ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/hashy_object.rb', line 23 def inspectable? return true if obj.is_a?(String) inspected = obj.inspect return false if inspected.match /#</ true end |
#inspectify ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hashy_object.rb', line 30 def inspectify return handle_hashy_array(obj).inspect if obj.class == Array return handle_hashy_hash(obj).inspect if obj.class == Hash return handle_hashy_to_hash(obj).inspect if obj.respond_to?(:to_hash) return handle_hashy_instance_variables(obj).inspect end |