Class: Solace::Tokens::Token
- Inherits:
-
Object
- Object
- Solace::Tokens::Token
- Defined in:
- lib/solace/tokens/token.rb
Overview
Represents a Solana token with its metadata.
A token object encapsulates the symbol and associated metadata for a Solana token. It provides dynamic access to metadata attributes via method calls. This class is used within the Solace::Tokens module to represent individual tokens loaded from a YAML configuration file.
Instance Attribute Summary collapse
- #metadata ⇒ Object readonly
- #symbol ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(symbol, metadata) ⇒ self
constructor
Initializes a new Token instance.
-
#inspect ⇒ String
Returns a string representation of the Token object.
-
#method_missing(name) ⇒ Object
Dynamically access metadata attributes.
-
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
Check if a metadata attribute exists.
Constructor Details
#initialize(symbol, metadata) ⇒ self
Initializes a new Token instance.
20 21 22 23 |
# File 'lib/solace/tokens/token.rb', line 20 def initialize(symbol, ) @symbol = symbol @metadata = .transform_keys(&:to_sym) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
Dynamically access metadata attributes.
30 31 32 33 34 |
# File 'lib/solace/tokens/token.rb', line 30 def method_missing(name, *) return [name] if .key?(name) super end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
13 14 15 |
# File 'lib/solace/tokens/token.rb', line 13 def @metadata end |
#symbol ⇒ Object (readonly)
13 14 15 |
# File 'lib/solace/tokens/token.rb', line 13 def symbol @symbol end |
Instance Method Details
#inspect ⇒ String
Returns a string representation of the Token object.
48 49 50 |
# File 'lib/solace/tokens/token.rb', line 48 def inspect "#<Solace::Token #{symbol} #{.inspect}>" end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
Check if a metadata attribute exists.
41 42 43 |
# File 'lib/solace/tokens/token.rb', line 41 def respond_to_missing?(name, _include_private = false) .key?(name) || super end |