Skip to content
Browse files

fix #inspect, #each_pair

  • Loading branch information...
1 parent cce248f commit d448712651dc8f3b3198807c42fcda3176602fe6 @kachick committed Aug 13, 2012
Showing with 60 additions and 4 deletions.
  1. +1 −0 Manifest.txt
  2. +1 −0 Rakefile
  3. +54 −0 declared/declared.rb
  4. +2 −1 examples/README.rb
  5. +1 −1 lib/structable/classmethods.rb
  6. +1 −2 lib/structable/instancemethods.rb
View
1 Manifest.txt
@@ -10,4 +10,5 @@ lib/structable/singletonclass.rb
lib/structable/version.rb
test/test_helper.rb
test/test_structable.rb
+declared/declared.rb
examples/README.rb
View
1 Rakefile
@@ -9,6 +9,7 @@ $hoe = Hoe.spec 'structable' do
self.rubyforge_name = name
require_ruby_version '>= 1.9.2'
dependency 'yard', '~> 0.8.2.1', :development
+ dependency 'declare', '~> 0.0.4', :development
end
require 'newgem/tasks'
View
54 declared/declared.rb
@@ -0,0 +1,54 @@
+#!/usr/local/bin/ruby -w
+
+$VERBOSE = true
+
+require_relative '../lib/structable'
+require 'declare'
+
+class Drink
+ include Structable
+
+ member :taste
+end
+
+class Tea < Drink
+ member :leaf
+ alias_member :type, :leaf
+end
+
+Declare do
+
+ The(Tea.new :bitter, :green) do |tea|
+ kind Structable
+
+ The tea.inspect do
+ is '#<Tea (Structable) taste=:bitter leaf=:green>'
+ end
+
+ The tea.each_member do |em|
+ a Enumerator
+
+ The em.to_a do
+ is [:taste, :leaf]
+ end
+ end
+
+ The tea.each_value do |ev|
+ a Enumerator
+
+ The ev.to_a do
+ is [:bitter, :green]
+ end
+ end
+
+ The tea.each_pair do |ep|
+ a Enumerator
+
+ The ep.to_a do
+ is [[:taste, :bitter], [:leaf, :green]]
+ end
+ end
+
+ end
+
+end
View
3 examples/README.rb
@@ -16,8 +16,9 @@ class Tea < Drink
end
tea = Tea.new :bitter, :green
+p tea #=> #<Tea (Structable) taste=:bitter leaf=:green>
p tea.members #=> [:taste, :leaf]
-p tea.members(true) #=> [:taste, :leaf, :type]
+p tea.members(true) #=> [:taste, :leaf, :type]
p tea.member? :type #=> true
tea.type = 'Special Flavor'
p tea.taste #=> :bitter
View
2 lib/structable/classmethods.rb
@@ -19,7 +19,7 @@ def length
# @return [Enumerator]
def each_member(&block)
return to_enum(__method__) unless block_given?
- _members.each_key(&block)
+ autonyms.each(&block)
self
end
View
3 lib/structable/instancemethods.rb
@@ -53,8 +53,7 @@ def eql?(other)
def inspect
"#<#{self.class} (Structable)".tap {|s|
each_pair do |name, value|
- suffix = (has_default?(name) && default?(name)) ? '(default)' : nil
- s << " #{name}=#{value.inspect}#{suffix}"
+ s << " #{name}=#{value.inspect}"
end
s << ">"

0 comments on commit d448712

Please sign in to comment.
Something went wrong with that request. Please try again.