Skip to content

Commit

Permalink
Use instance variable directly to avoid creating private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Apr 16, 2011
1 parent bac811c commit 48d94b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions lib/backports/1.9.1/proc.rb
Expand Up @@ -2,17 +2,14 @@
class Proc
# Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Proc.html]
def lambda?
!!is_lambda
!!@is_lambda
end

attr_accessor :is_lambda
private :is_lambda, :is_lambda=
end

class Method
def to_proc_with_lambda_tracking
proc = to_proc_without_lambda_tracking
proc.send :is_lambda=, true
proc.instance_variable_set :@is_lambda, true
proc
end
Backports.alias_method_chain self, :to_proc, :lambda_tracking
Expand Down
4 changes: 2 additions & 2 deletions lib/backports/tools.rb
Expand Up @@ -177,9 +177,9 @@ def self.alias_method(mod, new_name, old_name)

# Used internally to propagate #lambda?
def self.track_lambda(from, to, default = false)
is_lambda = from.send :is_lambda
is_lambda = from.instance_variable_get :@is_lambda
is_lambda = default if is_lambda.nil?
to.send :is_lambda=, is_lambda
to.instance_variable_set :@is_lambda, is_lambda
to
end

Expand Down

0 comments on commit 48d94b9

Please sign in to comment.