class Nvlope::Arguments

Constants

Error

Public Class Methods

new(hash) click to toggle source
# File lib/nvlope/arguments.rb, line 5
def initialize hash
  hash.respond_to?(:to_hash) or raise ArgumentError, "Arguments should be a hash"
  @hash = hash.to_hash
end

Public Instance Methods

[](key) click to toggle source
# File lib/nvlope/arguments.rb, line 10
def [] key
  @hash[key]
end
optional(key) { || ... } click to toggle source
# File lib/nvlope/arguments.rb, line 19
def optional key
  return @hash[key] if @hash.key?(key)
  return yield if block_given?
end
require(key) click to toggle source
# File lib/nvlope/arguments.rb, line 14
def require key
  return @hash[key] if @hash.key?(key)
  raise Error, "#{key} is a required option", caller(2)
end