class HashBuilder

Takes methods and builds an internal hash where the method calls are keys, and their parameter is the value.

Attributes

key_type[R]

Public Class Methods

new(key_type = String) click to toggle source
# File lib/sis_ruby/hash_builder.rb, line 8
def initialize(key_type = String)
  raise ArgumentError.new("Invalid key type '#{key_type}'") unless [String, Symbol].include?(key_type)
  @key_type = key_type
  @data = {}
end

Public Instance Methods

method_missing(method_name, *args) click to toggle source
# File lib/sis_ruby/hash_builder.rb, line 15
def method_missing(method_name, *args)
  value = args.first
  key = (@key_type == String) ? method_name.to_s : method_name.to_sym
  @data[key] = value
  self
end
respond_to_missing?(method_name, include_private) click to toggle source
# File lib/sis_ruby/hash_builder.rb, line 23
def respond_to_missing?(method_name, include_private)
  true  # TODO: exclude ancestor methods?
end
to_h() click to toggle source
# File lib/sis_ruby/hash_builder.rb, line 28
def to_h
  @data
end