Permalink
Browse files

Add '?' suffix to generated method names of bools

Objects with values that are either true or false have an '?' appended to
their name to fit with standard Ruby convention. For example, Repository
objects now have a .fork? and .private? method. This convention is not
reflected in the value of the @keys instance variable, because we assume
callers will use it to iterate through the instance variables, whose names do
not have a '?' suffix...

Note: This commit theoretically breaks backward compatibility, as the
unadorned method names no longer work.

This closes #2.
  • Loading branch information...
1 parent 402d96d commit 5b521b9cd0b9aef4d4f6c32480ae80b1dd68cfc7 @runpaint committed Apr 22, 2009
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/octopi/base.rb
View
@@ -40,11 +40,13 @@ def initialize(api, hash)
next if k =~ /\./
instance_variable_set("@#{k}", v)
- self.class.send :define_method, "#{k}=" do |v|
+ method = (TrueClass === v || FalseClass === v) ? "#{k}?" : k
+
+ self.class.send :define_method, "#{method}=" do |v|
instance_variable_set("@#{k}", v)
end
- self.class.send :define_method, k do
+ self.class.send :define_method, method do
instance_variable_get("@#{k}")
end
end

0 comments on commit 5b521b9

Please sign in to comment.