Sha256: 9746abc1e7dfa07809d2deddc83430ad7db08dc4d61878e15d7394a8fe76da44
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
= hashmake * {Homepage}[https://rubygems.org/gems/hashmake] * {Documentation}[http://rubydoc.info/gems/hashmake/frames] * {Email}[mailto:jamestunnell at lavabit.com] == Description Make hash-based object initialization easy! Provides hash_make method that can consider parameter name, type, default value, validation, requiredd/not, and container type (none/array/hash) according to the specification provided. By default it the value given with the arg key to to an instance variable of same name as parameter. == Features == Examples require 'hashmake' class MyClass include Hashmake::HashMakeable ARG_SPECS = [ ArgSpec.new(:key => :x, :reqd => true, :type => Float, :validator => ->(a){ a.between?(0.0,1.0) }), ArgSpec.new(:key => :y, :reqd => false, :type => Float, :validator => ->(a){ a.between?(0.0,1.0) }, :default => 0.0), ] attr_reader :x, :y def initialize hashed_args hash_make(ARG_SPECS, hashed_args) end end a = MyClass.new :x => 0.5 # a.x => 0.5, a.y => 0.0 a = MyClass.new :x => 0.5, :y => 0.2 # a.x => 0.5, a.y => 0.2 a = MyClass.new # raise ArgumentError because :x is reqd and not given a = MyClass.new :y => 0.5 # raise ArgumentError because :x is reqd and not given == Requirements == Install $ gem install hashmake == Copyright Copyright (c) 2013 James Tunnell See LICENSE.txt for details.
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hashmake-0.1.5 | README.rdoc |
hashmake-0.1.4 | README.rdoc |