Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.

Signed-off-by: Felipe Coury <felipe.coury@gmail.com>
  • Loading branch information...
commit 0299a1f1d7840c5e65f454b9090fef85d96a04ad 1 parent 1b902d3
@runpaint authored fcoury committed
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/octopi/base.rb
View
6 lib/octopi/base.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.