Permalink
Browse files

Oh, the things I do for Ruby 1.8 compatibility...

So, it turns out that in Ruby 1.8, methods defined with define_method
return an arity of -1 unless you explicitly state that no arguments are
passed. This breaks memoization, which currently only works on
zero-arity methods.
  • Loading branch information...
1 parent 4a67d25 commit 5377cc98b9fbb59fb1a9f6245f0c08961285f928 @sferik committed Nov 18, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/twitter/base.rb
View
@@ -73,7 +73,7 @@ def display_uri_attr_reader
# @param key1 [Symbol]
# @param key2 [Symbol]
def define_uri_method(key1, key2)
- define_method(key1) do
+ define_method(key1) do ||
URI.parse(@attrs[key2]) if @attrs[key2]
end
memoize(key1)
@@ -85,7 +85,7 @@ def define_uri_method(key1, key2)
# @param klass [Symbol]
# @param key2 [Symbol]
def define_attribute_method(key1, klass=nil, key2=nil)
- define_method(key1) do
+ define_method(key1) do ||
if klass.nil?
@attrs[key1]
else
@@ -105,7 +105,7 @@ def define_attribute_method(key1, klass=nil, key2=nil)
# @param key1 [Symbol]
# @param key2 [Symbol]
def define_predicate_method(key1, key2=key1)
- define_method(:"#{key1}?") do
+ define_method(:"#{key1}?") do ||
!!@attrs[key2]
end
memoize(:"#{key1}?")

0 comments on commit 5377cc9

Please sign in to comment.