Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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.
  • Loading branch information...
commit 5b521b9cd0b9aef4d4f6c32480ae80b1dd68cfc7 1 parent 402d96d
@runpaint authored
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.