Skip to content

keita/naming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

naming

naming is a Ruby library for generating classes that consist from name and value. You can name objects and collect values by it.

Gem Version Build Status Coverage Status Code Climate

Installation

$ gem install naming

Usage

Basic

#
# 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) #=> [2]
# collect objects excluding naming objects
Naming.others(list)    #=> ["abc", 123, nil]

Case Selecting

#
# case control flow with name
#
def message(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
message(Naming.A(1)) #=> "This is case A: 1"
message(Naming.B(2)) #=> "This is case B: 2"
message(true) #=> "This is case others: true"

Name Set

#
# collect objects by name set
#
list = [
  Naming.A(1),
  Naming.B(2),
  "abc",
  Naming.C(3),
  123,
  nil
]
# collect values of A and B
Naming[:A, :B].values(list) #=> [1, 2]
# collect others
Naming[:A, :B].others(list) #=> ["abc", Naming.C(3), 123, nil]

License

naming is free software distributed under MIT license.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

naming is a ruby library for providing name and value container with useful functions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages