Sha256: 7ac38edc099a91d26cca3e165a159333e285e8ce7b349ee7642baac90579730a
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
h1. renum h1. → 'renum' h2. What Renum provides a readable but terse enum facility for Ruby. h2. Installing <pre syntax="ruby">sudo gem install renum</pre> h2. Demonstration of usage Renum allows you to do something like this: <pre syntax="ruby">enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]</pre> and this: <pre syntax="ruby">enum :Color, [ :RED, :GREEN, :BLUE ] do def abbr name[0..0] end end</pre> Giving you something that satisfies this spec: <pre syntax="ruby">describe "enum" do it "creates a class for the value type" do Status.class.should == Class end it "makes each value an instance of the value type" do Status::NOT_STARTED.class.should == Status end it "exposes array of values" do Status.values.should == [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE] end it "enumerates over values" do Status.map {|s| s.name}.should == %w[NOT_STARTED IN_PROGRESS COMPLETE] end it "indexes values" do Status[2].should == Status::COMPLETE Color[0].should == Color::RED end it "provides index lookup on values" do Status::IN_PROGRESS.index.should == 1 Color::GREEN.index.should == 1 end it "allows an associated block to define instance methods" do Color::RED.abbr.should == "R" end it "provides a reasonable to_s for values" do Status::NOT_STARTED.to_s.should == "Status::NOT_STARTED" end end</pre> h2. License This code is free to use under the terms of the MIT license. h2. Contact Renum was created by John D. Hume. Comments are welcome. Send an email to duelin dot markers at gmail or "contact me via my blog":http://elhumidor.blogspot.com/.
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
renum-0.0.1 | website/index.txt |