Skip to content

Commit

Permalink
Add '?' suffix to generated method names of bools
Browse files Browse the repository at this point in the history
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 fcoury#2.
  • Loading branch information
runpaint committed Apr 22, 2009
1 parent 402d96d commit 5b521b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/octopi/base.rb
Expand Up @@ -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
Expand Down

0 comments on commit 5b521b9

Please sign in to comment.