naming is a ruby library for generating classes that consist from name and value. You can get naming class by sending class method ++ with the name.
$ gem install naming
# # naming object of A with the value 123 # a = Naming.A(123) a.value #=> 123 a.name #=> :A a.class #=> Naming::A
Collect values by name from array
# # collect objects by name # list = [ Naming.A(1), Naming.B(2), "abc", Naming.A(3), 123, nil ] # collect values of A objects Naming::A.values(list) #=> [1, 3] # collect values of B objects Naming::B.values(list) #=>  # collect objects excluding naming objects Naming.others(list) #=> ["abc", 123, nil]
# # case control flow with name # def (obj) case obj when Naming::A "This is case A: %s" % obj.value when Naming::B "This is case B: %s" % obj.value else "This is case others: %s" % obj end end (Naming.A(1)) #=> "This is case A: 1" (Naming.B(2)) #=> "This is case B: 2" (true) #=> "This is case others: true"
naming is free software distributed under MIT licence.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request