Class: AttributeStruct
- Inherits:
- BasicObject
- Defined in:
- lib/attribute_struct/base.rb,
lib/attribute_struct/version.rb,
lib/attribute_struct/augmented.rb,
lib/attribute_struct/irb_compat.rb,
lib/attribute_struct/monkey_camels.rb,
lib/attribute_struct/attribute_hash.rb,
lib/attribute_struct/attribute_struct.rb
Overview
Helper methods for IRB interactions
Direct Known Subclasses
Defined Under Namespace
Modules: IrbCompat, MonkeyCamels Classes: Augmented, CamelString, CollapseArray, Mash
Constant Summary collapse
- VERSION =
Current library version
::Gem::Version.new("0.5.1")
- AttributeHash =
Mash
- VALID_CAMEL_STYLES =
Returns valid styles and mapped value.
{ :bactrian => :no_leading, :no_leading_hump => :no_leading, :no_leading => :no_leading, :dromedary => :leading, :leading_hump => :leading, :leading => :leading, }
- UNSET_VALUE =
value used to identify unset value
:__unset__
Class Attribute Summary collapse
-
.camel_keys ⇒ Truthy, Falsey
Global flag for camel keys.
-
.camel_style ⇒ Symbol
Camel key style.
Instance Attribute Summary collapse
-
#_arg_state ⇒ AtributeStruct::AttributeHash, Mash
(also: #arg_state!)
readonly
Holding space for state.
-
#_camel_keys ⇒ Truthy, Falsey
(also: #camel_keys!)
Current camelizing setting.
-
#_camel_style ⇒ Symbol
(also: #camel_style!)
Current camel style.
Class Method Summary collapse
-
.build(&block) ⇒ Object
Create AttributeStruct instance and dump the resulting hash.
- .hashish ⇒ AttributeStruct::AttributeHash
-
.irb_compat! ⇒ TrueClass
Enable IRB compatibility mode.
-
.load_the_camels ⇒ Object
Loads helpers for camel casing.
-
.validate_camel_style(style) ⇒ Symbol
Validate requested camel style and return mapped value used internally.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Direct data access.
-
#__hashish ⇒ Class
Hashish type available.
-
#_array(*args) ⇒ Array
(also: #array!)
Create an Array and evaluate discovered AttributeStructs.
-
#_build { ... } ⇒ Object
(also: #build!)
Execute block within current context.
-
#_camel_keys_action ⇒ Symbol, NilClass
:auto_disable or :auto_enable.
-
#_camel_keys_set(v) ⇒ Symbol
(also: #camel_keys_set!)
Set custom rule for processed keys at this context level.
-
#_clone(_new_parent = nil) ⇒ AttributeStruct
(also: #clone!)
Clone of current instance.
-
#_data ⇒ AttributeStruct::AttributeHash, Mash
(also: #data!)
Underlying struct data.
-
#_deep_copy(thing = nil) ⇒ Object
Create a “deep” copy.
-
#_delete(key) ⇒ Object
(also: #delete!)
Delete entry from struct.
-
#_do_dup(v) ⇒ Object
Provide dup of instance.
-
#_dump ⇒ AttributeStruct::AttributeHash, Mash
(also: #dump!)
Dump struct to hashish.
-
#_dump_unpacker(item) ⇒ Object
Process and unpack items for dumping within deeply nested enumerable types.
-
#_kernelify ⇒ TrueClass
(also: #kernelify!)
Inject Kernel methods.
-
#_keys ⇒ Array<String,Symbol>
(also: #keys!)
Keys within struct.
-
#_klass ⇒ Class
This class.
-
#_klass_new(*args, &block) ⇒ AttributeStruct
New struct instance.
-
#_load(hashish) ⇒ self
(also: #load!)
Clear current struct data and replace.
-
#_merge(overlay) ⇒ AttributeStruct
Perform deep merge.
-
#_merge!(overlay) ⇒ self
Perform deep merge in place.
-
#_objectified_constant_lookup(konst) ⇒ Object, NilClass
Lookup constant in root namespace.
-
#_objectify(enable = true) ⇒ TrueClass, FalseClass
(also: #objectify!)
Enable/disable root constant lookups.
-
#_parent(obj = nil) ⇒ AttributeStruct, NilClass
(also: #parent!)
Parent of this struct.
-
#_process_key(key, *args) ⇒ String, Symbol
(also: #process_key!)
Provide expected key format based on context.
-
#_root ⇒ AttributeStruct, NilClass
(also: #root!)
Root of the struct or nil if self is root.
-
#_set(key, val = UNSET_VALUE) { ... } ⇒ Object
(also: #set!)
Directly set value into struct.
-
#_set_state(args = {}) ⇒ Hashish
(also: #set_state!)
Set state into current context.
-
#_state(key, traverse = true) ⇒ Object, NilClass
(also: #state!)
Value of requested state.
- #hash ⇒ Numeric
-
#initialize(init_hash = nil) { ... } ⇒ AttributeStruct
constructor
Create new instance.
-
#is_a?(klass) ⇒ TrueClass, FalseClass
(also: #kind_of?)
Determine if self is a class.
-
#kernelified? ⇒ TrueClass, FalseClass
Kernel methods have been injected.
-
#key?(key) ⇒ TrueClass, FalseClass
(also: #has_key?)
Check if key exists within struct.
-
#klass! ⇒ Class
(also: #class!, #class)
This clas.
-
#method_missing(_sym, *_args) { ... } ⇒ Object
Provides struct DSL behavior.
-
#nil? ⇒ TrueClass, FalseClass
Struct is nil (empty data).
- #objectified? ⇒ TrueClass, FalseClass
-
#present? ⇒ TrueClass, FalseClass
Struct is present (not empty).
-
#respond_to?(name) ⇒ TrueClass, FalseClass
Instance responds to method name.
Constructor Details
#initialize(init_hash = nil) { ... } ⇒ AttributeStruct
Create new instance
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/attribute_struct/attribute_struct.rb', line 107 def initialize(init_hash = nil, &block) @_camel_keys = _klass.camel_keys @_camel_keys_set = nil @_parent = nil @_arg_state = __hashish.new @_kernelified = false @_objectified = false @table = __hashish.new if (init_hash) _load(init_hash) end if (block) self.instance_exec(&block) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(_sym, *_args) { ... } ⇒ Object
Dragons and unicorns all over in here
Provides struct DSL behavior
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/attribute_struct/attribute_struct.rb', line 224 def method_missing(_sym, *_args, &_block) if (objectified? && _args.empty? && _block.nil?) _o_lookup = _objectified_constant_lookup(_sym) return _o_lookup if _o_lookup end if (_sym.is_a?(::String) || _sym.is_a?(::Symbol)) if ((_s = _sym.to_s).end_with?("=")) _s.slice!(-1, _s.length) _sym = _s end _sym = _process_key(_sym) end if (!_args.empty? || _block) if (_args.empty? && _block) _base = @table.fetch(_sym, UNSET_VALUE) if (_state(:value_collapse) && !_base.is_a?(self.class!)) _orig = _base _base = _klass_new else unless (_base.is_a?(self.class!)) _base = _klass_new end end @table[_sym] = _base if (_block.arity == 0) _base.instance_exec(&_block) else _base.instance_exec(_base, &_block) end if (_orig.is_a?(::NilClass)) @table[_sym] = _base else if (_orig == UNSET_VALUE) @table[_sym] = _base else unless (_orig.is_a?(CollapseArray)) _orig = CollapseArray.new.push(_orig) end _orig << _base @table[_sym] = _orig end end elsif (!_args.empty? && _block) _result = _leaf = _base = @table.fetch(_sym, _klass_new) @table[_sym] = _result _args.flatten.each do |_arg| _leaf = _base[_arg] unless (_leaf.is_a?(_klass)) _leaf = _klass_new _base._set(_arg, _leaf) _base = _leaf end end if (!_leaf.nil? && _state(:value_collapse)) _orig = _leaf _leaf = _orig.parent._klass_new end _block.arity == 0 ? _leaf._build(&_block) : _leaf._build(_leaf, &_block) if (_orig) unless (_orig.is_a?(CollapseArray)) _orig = CollapseArray.new.push(_orig) end _orig << _leaf else _orig = _leaf end else if (_args.size > 1 && _args.all? { |_i| _i.is_a?(::String) || _i.is_a?(::Symbol) } && !_state(:value_collapse)) @table[_sym] = _klass_new unless @table[_sym].is_a?(_klass) _endpoint = _args.inject(@table[_sym]) do |_memo, _k| unless (_memo[_k].is_a?(_klass)) _memo._set(_k, _klass_new) end _memo[_k] end return _endpoint # custom break out else if (_args.size > 1) _val = _args.map do |_v| if (_v.is_a?(::Hash) && _state(:hash_load_struct)) _val = _klass_new _val._load(_v) else _v end end else if (_args.first.is_a?(::Hash) && _state(:hash_load_struct)) _val = _klass_new _val._load(_args.first) else _val = _args.first end end if (_state(:value_collapse) && !(_leaf = @table[_sym]).nil?) unless (_leaf.is_a?(CollapseArray)) _leaf = CollapseArray.new.push(_leaf) end _leaf << _val @table[_sym] = _leaf else @table[_sym] = _val end end end end @table[_sym] = _klass_new if @table[_sym].nil? && !@table[_sym].is_a?(_klass) @table[_sym] end |
Class Attribute Details
.camel_keys ⇒ Truthy, Falsey
Returns global flag for camel keys.
21 22 23 |
# File 'lib/attribute_struct/attribute_struct.rb', line 21 def camel_keys @camel_keys end |
.camel_style ⇒ Symbol
Returns camel key style.
23 24 25 |
# File 'lib/attribute_struct/attribute_struct.rb', line 23 def camel_style @camel_style end |
Instance Attribute Details
#_arg_state ⇒ AtributeStruct::AttributeHash, Mash (readonly) Also known as: arg_state!
Returns holding space for state.
100 101 102 |
# File 'lib/attribute_struct/attribute_struct.rb', line 100 def _arg_state @_arg_state end |
#_camel_keys ⇒ Truthy, Falsey Also known as: camel_keys!
Returns current camelizing setting.
94 95 96 |
# File 'lib/attribute_struct/attribute_struct.rb', line 94 def _camel_keys @_camel_keys end |
#_camel_style ⇒ Symbol Also known as: camel_style!
Returns current camel style.
97 98 99 |
# File 'lib/attribute_struct/attribute_struct.rb', line 97 def _camel_style @_camel_style end |
Class Method Details
.build(&block) ⇒ Object
Create AttributeStruct instance and dump the resulting hash
72 73 74 75 |
# File 'lib/attribute_struct/attribute_struct.rb', line 72 def build(&block) raise ArgumentError.new "Block required for build!" unless block new(&block)._dump end |
.hashish ⇒ AttributeStruct::AttributeHash
67 68 69 |
# File 'lib/attribute_struct/attribute_struct.rb', line 67 def hashish ::AttributeStruct::AttributeHash end |
.irb_compat! ⇒ TrueClass
this will add methods required for working within IRB
Enable IRB compatibility mode
81 82 83 84 |
# File 'lib/attribute_struct/attribute_struct.rb', line 81 def irb_compat! self.send(:include, IrbCompat) true end |
.load_the_camels ⇒ Object
Loads helpers for camel casing
59 60 61 62 63 64 |
# File 'lib/attribute_struct/attribute_struct.rb', line 59 def load_the_camels unless defined?(@camels_loaded) require "attribute_struct/monkey_camels" @camels_loaded = true end end |
.validate_camel_style(style) ⇒ Symbol
Validate requested camel style and return mapped value used internally
48 49 50 51 52 53 54 55 56 |
# File 'lib/attribute_struct/attribute_struct.rb', line 48 def validate_camel_style(style) if (VALID_CAMEL_STYLES.has_key?(style)) VALID_CAMEL_STYLES[style] else valid_types = VALID_CAMEL_STYLES.keys(&:inspect).join(", ") raise ArgumentError.new "Unsupported camel style provided " \ "`#{style.inspect}`! (Allowed: #{valid_types})" end end |
Instance Method Details
#[](key) ⇒ Object
Direct data access
196 197 198 |
# File 'lib/attribute_struct/attribute_struct.rb', line 196 def [](key) _data[_process_key(key)] end |
#__hashish ⇒ Class
Returns hashish type available.
482 483 484 |
# File 'lib/attribute_struct/attribute_struct.rb', line 482 def __hashish ::AttributeStruct::AttributeHash end |
#_array(*args) ⇒ Array Also known as: array!
Create an Array and evaluate discovered AttributeStructs
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/attribute_struct/attribute_struct.rb', line 616 def _array(*args) args.map do |maybe_block| if (maybe_block.is_a?(::Proc)) klass = _klass_new if (maybe_block.arity > 0) klass.instance_exec(klass, &maybe_block) else klass.instance_exec(&maybe_block) end klass else maybe_block end end end |
#_build { ... } ⇒ Object Also known as: build!
Execute block within current context
127 128 129 |
# File 'lib/attribute_struct/attribute_struct.rb', line 127 def _build(&block) self.instance_exec(&block) end |
#_camel_keys_action ⇒ Symbol, NilClass
Returns :auto_disable or :auto_enable.
589 590 591 |
# File 'lib/attribute_struct/attribute_struct.rb', line 589 def _camel_keys_action @_camel_keys_set end |
#_camel_keys_set(v) ⇒ Symbol Also known as: camel_keys_set!
Set custom rule for processed keys at this context level
582 583 584 |
# File 'lib/attribute_struct/attribute_struct.rb', line 582 def _camel_keys_set(v) @_camel_keys_set = v end |
#_clone(_new_parent = nil) ⇒ AttributeStruct Also known as: clone!
Returns clone of current instance.
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/attribute_struct/attribute_struct.rb', line 678 def _clone(_new_parent = nil) _cloned_inst = _klass_new _cloned_inst._data.replace __hashish[ @table.map { |_key, _value| if (_key.is_a?(::AttributeStruct)) _key = _key._clone else _key = _do_dup(_key) end if (_value.is_a?(::AttributeStruct)) _value = _value._clone else _value = _do_dup(_value) end [_key, _value] } ] _cloned_inst._parent(_new_parent) if _new_parent _cloned_inst end |
#_data ⇒ AttributeStruct::AttributeHash, Mash Also known as: data!
Returns underlying struct data.
373 374 375 |
# File 'lib/attribute_struct/attribute_struct.rb', line 373 def _data @table end |
#_deep_copy(thing = nil) ⇒ Object
Create a “deep” copy
503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/attribute_struct/attribute_struct.rb', line 503 def _deep_copy(thing = nil) thing ||= _dump if (thing.is_a?(::Enumerable)) val = thing.map { |v| v.is_a?(::Enumerable) ? _deep_copy(v) : _do_dup(v) } else val = _do_dup(thing) end if (thing.is_a?(::Hash)) val = __hashish[*val.flatten(1)] end val end |
#_delete(key) ⇒ Object Also known as: delete!
Delete entry from struct
383 384 385 |
# File 'lib/attribute_struct/attribute_struct.rb', line 383 def _delete(key) _data.delete(_process_key(key)) end |
#_do_dup(v) ⇒ Object
if Symbol provided, String is returned
Provide dup of instance
491 492 493 494 495 496 497 |
# File 'lib/attribute_struct/attribute_struct.rb', line 491 def _do_dup(v) begin v.dup rescue v.is_a?(::Symbol) ? v.to_s : v end end |
#_dump ⇒ AttributeStruct::AttributeHash, Mash Also known as: dump!
Returns dump struct to hashish.
417 418 419 420 421 422 423 424 |
# File 'lib/attribute_struct/attribute_struct.rb', line 417 def _dump processed = @table.keys.map do |key| value = @table[key] val = _dump_unpacker(value) [_dump_unpacker(key), val] unless val == UNSET_VALUE end.compact __hashish[*processed.flatten(1)] end |
#_dump_unpacker(item) ⇒ Object
Process and unpack items for dumping within deeply nested enumerable types
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/attribute_struct/attribute_struct.rb', line 394 def _dump_unpacker(item) if (item.is_a?(::Enumerable)) if (item.respond_to?(:keys)) item.class[ *item.map do |entry| _dump_unpacker(entry) end.flatten(1) ] else item.class[ *item.map do |entry| _dump_unpacker(entry) end ] end elsif (item.is_a?(::AttributeStruct)) item.nil? ? UNSET_VALUE : item._dump else item end end |
#_kernelify ⇒ TrueClass Also known as: kernelify!
Inject Kernel methods
655 656 657 658 659 660 661 662 663 |
# File 'lib/attribute_struct/attribute_struct.rb', line 655 def _kernelify unless (kernelified?) @_kernelified = true (::Kernel.public_instance_methods + ::Kernel.private_instance_methods).each do |m_name| self.instance_eval("def #{m_name}(*a, &b); ::Kernel.instance_method(:#{m_name}).bind(self).curry.call(*a, &b); end") end end true end |
#_keys ⇒ Array<String,Symbol> Also known as: keys!
Returns keys within struct.
366 367 368 |
# File 'lib/attribute_struct/attribute_struct.rb', line 366 def _keys _data.keys end |
#_klass ⇒ Class
Returns this class.
551 552 553 |
# File 'lib/attribute_struct/attribute_struct.rb', line 551 def _klass ::AttributeStruct end |
#_klass_new(*args, &block) ⇒ AttributeStruct
will set self as parent and propogate camelizing status
Returns new struct instance.
565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/attribute_struct/attribute_struct.rb', line 565 def _klass_new(*args, &block) n = _klass.new(*args, &block) unless (_camel_keys_action == :auto_discovery) n._camel_keys_set(_camel_keys_action) end n._camel_keys = _camel_keys n._camel_style = _camel_style if _camel_style n._objectify if objectified? n._kernelify if kernelified? n._parent(self) n end |
#_load(hashish) ⇒ self Also known as: load!
Clear current struct data and replace
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/attribute_struct/attribute_struct.rb', line 432 def _load(hashish) @table.clear if (_root._camel_keys_action == :auto_discovery) starts = hashish.keys.map { |k| k[0, 1] } unless (starts.detect { |k| k =~ /[A-Z]/ }) _camel_keys_set(:auto_disable) else _camel_keys_set(:auto_enable) unless _parent.nil? end end hashish.each do |key, value| if (value.is_a?(::Enumerable)) flat = value.map do |v| v.is_a?(::Hash) ? _klass_new(v) : v end value = value.is_a?(::Hash) ? __hashish[*flat.flatten(1)] : flat end if (value.is_a?(::Hash)) self._set(key)._load(value) else self._set(key, value) end end self end |
#_merge(overlay) ⇒ AttributeStruct
Perform deep merge
464 465 466 467 468 469 |
# File 'lib/attribute_struct/attribute_struct.rb', line 464 def _merge() source = _deep_copy dest = ._deep_copy result = source.deep_merge(dest) _klass_new(result) end |
#_merge!(overlay) ⇒ self
Perform deep merge in place
475 476 477 478 479 |
# File 'lib/attribute_struct/attribute_struct.rb', line 475 def _merge!() result = _merge()._dump _load(result) self end |
#_objectified_constant_lookup(konst) ⇒ Object, NilClass
Lookup constant in root namespace
646 647 648 649 650 |
# File 'lib/attribute_struct/attribute_struct.rb', line 646 def _objectified_constant_lookup(konst) if (konst.to_s[0].match(/[A-Z]/) && ::Object.const_defined?(konst)) ::Object.const_get(konst) end end |
#_objectify(enable = true) ⇒ TrueClass, FalseClass Also known as: objectify!
Enable/disable root constant lookups
181 182 183 |
# File 'lib/attribute_struct/attribute_struct.rb', line 181 def _objectify(enable = true) @_objectified = !!enable end |
#_parent(obj = nil) ⇒ AttributeStruct, NilClass Also known as: parent!
Returns parent of this struct.
594 595 596 597 |
# File 'lib/attribute_struct/attribute_struct.rb', line 594 def _parent(obj = nil) @_parent = obj if obj @_parent end |
#_process_key(key, *args) ⇒ String, Symbol Also known as: process_key!
Provide expected key format based on context
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/attribute_struct/attribute_struct.rb', line 521 def _process_key(key, *args) if (key.is_a?(::String) || key.is_a?(::Symbol)) key = CamelString.new(key.to_s) if (_camel_keys && _camel_keys_action && !key._hump_format_requested?) case _camel_keys_action when :auto_disable key._no_hump when :auto_enable key._hump end end if (_camel_keys && (key._camel? || args.include?(:force))) camel_args = [key] if (key._hump_style || _camel_style == :no_leading) unless (key._hump_style == :leading_hump) camel_args << false end end ::Bogo::Utility.camel(*camel_args) else key end else key end end |
#_root ⇒ AttributeStruct, NilClass Also known as: root!
Returns root of the struct or nil if self is root.
602 603 604 605 606 607 608 |
# File 'lib/attribute_struct/attribute_struct.rb', line 602 def _root r = self until (r._parent == nil) r = r._parent end r end |
#_set(key, val = UNSET_VALUE) { ... } ⇒ Object Also known as: set!
Directly set value into struct. Useful when the key is not valid ruby syntax for a method
207 208 209 210 211 212 213 |
# File 'lib/attribute_struct/attribute_struct.rb', line 207 def _set(key, val = UNSET_VALUE, &block) if (val != UNSET_VALUE) self.method_missing(key, val, &block) else self.method_missing(key, &block) end end |
#_set_state(args = {}) ⇒ Hashish Also known as: set_state!
Set state into current context
137 138 139 |
# File 'lib/attribute_struct/attribute_struct.rb', line 137 def _set_state(args = {}) _arg_state.merge!(args) end |
#_state(key, traverse = true) ⇒ Object, NilClass Also known as: state!
Value of requested state
148 149 150 151 152 153 154 155 156 |
# File 'lib/attribute_struct/attribute_struct.rb', line 148 def _state(key, traverse = true) if (_arg_state.has_key?(key)) _arg_state[key] else if (traverse && _parent) _parent._state(key) end end end |
#hash ⇒ Numeric
673 674 675 |
# File 'lib/attribute_struct/attribute_struct.rb', line 673 def hash ::Kernel.instance_method(:hash).bind(self).curry.call end |
#is_a?(klass) ⇒ TrueClass, FalseClass Also known as: kind_of?
Determine if self is a class
349 350 351 |
# File 'lib/attribute_struct/attribute_struct.rb', line 349 def is_a?(klass) (_klass.ancestors + [::AttributeStruct]).include?(klass) end |
#kernelified? ⇒ TrueClass, FalseClass
Returns Kernel methods have been injected.
668 669 670 |
# File 'lib/attribute_struct/attribute_struct.rb', line 668 def kernelified? !!@_kernelified end |
#key?(key) ⇒ TrueClass, FalseClass Also known as: has_key?
Check if key exists within struct
359 360 361 |
# File 'lib/attribute_struct/attribute_struct.rb', line 359 def key?(key) self._keys.include?(_process_key(key)) end |
#klass! ⇒ Class Also known as: class!, class
Returns this clas.
556 557 558 |
# File 'lib/attribute_struct/attribute_struct.rb', line 556 def klass! _klass end |
#nil? ⇒ TrueClass, FalseClass
Returns struct is nil (empty data).
336 337 338 |
# File 'lib/attribute_struct/attribute_struct.rb', line 336 def nil? _data.empty? end |
#objectified? ⇒ TrueClass, FalseClass
188 189 190 |
# File 'lib/attribute_struct/attribute_struct.rb', line 188 def objectified? @_objectified end |
#present? ⇒ TrueClass, FalseClass
Returns struct is present (not empty).
341 342 343 |
# File 'lib/attribute_struct/attribute_struct.rb', line 341 def present? !nil? end |
#respond_to?(name) ⇒ TrueClass, FalseClass
Instance responds to method name
638 639 640 |
# File 'lib/attribute_struct/attribute_struct.rb', line 638 def respond_to?(name) _klass.instance_methods.map(&:to_sym).include?(name.to_sym) end |