Module: Nis::Util::Assignable
- Included in:
- Struct::AccountImportanceViewModel, Struct::AccountInfo, Struct::AccountMetaData, Struct::AccountMetaDataPair, Struct::AccountPrivateKeyTransactionsPage, Struct::ApplicationMetaData, Struct::AuditCollection, Struct::AuditInfo, Struct::Block, Struct::BlockHeight, Struct::BlockScore, Struct::BootNodeRequest, Struct::Error, Struct::ExplorerBlockViewModel, Struct::ExplorerTransferViewModel, Struct::ExplorerViewModelTransaction, Struct::ExtendedNodeExperiencePair, Struct::HarvestInfo, Struct::KeyPairViewModel, Struct::Mosaic, Struct::MosaicDefinition, Struct::MosaicDefinitionMetaData, Struct::MosaicDefinitionMetaDataPair, Struct::MosaicId, Struct::MosaicLevy, Struct::MosaicProperties, Struct::MosaicSupply, Struct::MultisigCosignatoryModification, Struct::Namespace, Struct::NamespaceMetaData, Struct::NamespaceMetaDataPair, Struct::NemAnnounceResult, Struct::NemAsyncTimerVisitor, Struct::NemRequestResult, Struct::NetworkTime, Struct::NisNodeInfo, Struct::Node, Struct::NodeCollection, Struct::NodeExperience, Struct::RequestAnnounce, Struct::RequestPrepareAnnounce, Struct::TimeSynchronizationResult, Struct::Transaction, Struct::TransactionMetaData, Struct::TransactionMetaDataPair, Struct::UnconfirmedTransactionMetaData, Struct::UnconfirmedTransactionMetaDataPair
- Defined in:
- lib/nis/util/assignable.rb
Instance Method Summary collapse
-
#[](attr) ⇒ Any
Attribute value.
- #initialize(attributes = {}) {|_self| ... } ⇒ Object
-
#to_hash ⇒ Hash
Attribute and value pairs.
-
#to_json(state = nil) ⇒ String
JSON formatted structure.
Instance Method Details
#[](attr) ⇒ Any
Returns Attribute value.
12 13 14 |
# File 'lib/nis/util/assignable.rb', line 12 def [](attr) send(attr) end |
#initialize(attributes = {}) {|_self| ... } ⇒ Object
3 4 5 6 7 8 |
# File 'lib/nis/util/assignable.rb', line 3 def initialize(attributes = {}) attributes.each do |k, v| send("#{k.to_s}=", v) if respond_to?("#{k.to_s}=") end if attributes yield self if block_given? end |
#to_hash ⇒ Hash
Returns Attribute and value pairs.
17 18 19 20 21 22 |
# File 'lib/nis/util/assignable.rb', line 17 def to_hash hashed_properties = instance_variables.each_with_object({}) do |var, hash| hash[var.to_s.delete('@').to_sym] = instance_variable_get(var) end hashnize(hashed_properties) end |
#to_json(state = nil) ⇒ String
Returns JSON formatted structure.
25 26 27 |
# File 'lib/nis/util/assignable.rb', line 25 def to_json(state = nil) to_hash.to_json(state) end |