class Bizside::Config

Public Class Methods

new(hash = {}) click to toggle source
# File lib/bizside/config.rb, line 11
def initialize(hash = {})
  @hash = hash || {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/bizside/config.rb, line 15
def [](key)
  key = key.to_s
  return (@hash[key[0..-2]] ? true : false) if key.end_with?('?')

  ret = @hash[key]
  if ret.nil?
    ret = self.class.new
  elsif ret.is_a?(Hash)
    ret = self.class.new(ret)
  end

  ret
end
[]=(key, value) click to toggle source
# File lib/bizside/config.rb, line 29
def []=(key, value)
  value = self.class.new(value) if value.is_a?(Hash)
  @hash[key.to_s] = value
end
empty?() click to toggle source

Hash継承時代での互換維持のために実装

# File lib/bizside/config.rb, line 39
def empty?
  @hash.empty?
end
method_missing(name, *args) click to toggle source
# File lib/bizside/config.rb, line 52
def method_missing(name, *args)
  ret = self[name]

  if ret.is_a?(Hash) || ret.is_a?(::Bizside::Config)
    unless args[0].nil?
      ret = self[name] = args[0]
    end
  end

  ret
end
to_h() click to toggle source
# File lib/bizside/config.rb, line 34
def to_h
  @hash.dup
end
to_hash() click to toggle source

オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれるメソッド Hash継承時代での互換維持のために実装。 なお、Hashの継承時代でも @hash を活用していたので、空ハッシュを返す @see docs.ruby-lang.org/ja/latest/method/Object/i/to_hash.html

# File lib/bizside/config.rb, line 47
def to_hash
  warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed."
  {}
end