Class: Houston::HashDsl
- Inherits:
-
Object
- Object
- Houston::HashDsl
- Defined in:
- lib/configuration.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
(also: #to_hash, #to_h)
readonly
Returns the value of attribute hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ HashDsl
constructor
A new instance of HashDsl.
- #method_missing(method_name, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ HashDsl
Returns a new instance of HashDsl.
498 499 500 |
# File 'lib/configuration.rb', line 498 def initialize @hash = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
510 511 512 513 514 515 516 517 518 |
# File 'lib/configuration.rb', line 510 def method_missing(method_name, *args, &block) if block_given? @hash[method_name] = HashDsl.hash_from_block(block) elsif args.length == 1 @hash[method_name] = args.first else super end end |
Instance Attribute Details
#hash ⇒ Object (readonly) Also known as: to_hash, to_h
Returns the value of attribute hash.
494 495 496 |
# File 'lib/configuration.rb', line 494 def hash @hash end |
Class Method Details
.from_block(block) ⇒ Object
502 503 504 |
# File 'lib/configuration.rb', line 502 def self.from_block(block) HashDsl.new.tap { |dsl| dsl.instance_eval(&block) } end |
.hash_from_block(block) ⇒ Object
506 507 508 |
# File 'lib/configuration.rb', line 506 def self.hash_from_block(block) from_block(block).to_hash end |