Project

General

Profile

Actions

Bug #1135

closed

Problem renaming CMath.hypot in Ruby1.9

Added by wedesoft (Jan Wedekind) about 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.1p0 (2009-01-30 revision 21907) [x86_64-linux]
Backport:
[ruby-core:21953]

Description

=begin

Running the following program with Ruby1.9 ...

require 'complex'
class Module
def alias_method_chain( target, feature )
alias_method "#{target}without#{feature}", target
alias_method target, "#{target}with#{feature}"
end
end
Math.module_eval do
define_method( :hypot_with_test ) do |a,b|
puts "hypot_with_test( #{a}, #{b} )"
hypot_without_test( a, b )
end
alias_method_chain :hypot, :test
module_function :hypot_without_test
module_function :hypot
end
puts Math.hypot( 3, 4 )

... results in this error:

t.rb:14:in module_function': undefined method hypot_without_test' for module `CMath' (NameError)

from t.rb:14:in `block in '

from t.rb:8:in `module_eval'

from t.rb:8:in `

Using Ruby 1.8.6 the same program runs without error. The problem also does not occur if 'complex' is not loaded.

=end

Actions #1

Updated by tadf (tadayoshi funaba) about 15 years ago

=begin
I wrote an independence version.
It seems to be defference between them evaluaters.

module CMath
include Math
module_function :hypot
end

Object.instance_eval{remove_const :Math}
Math = CMath

class Module
def alias_method_chain( target, feature )
alias_method "#{target}without#{feature}", target
alias_method target, "#{target}with#{feature}"
end
end
Math.module_eval do
define_method( :hypot_with_test ) do |a,b|
puts "hypot_with_test( #{a}, #{b} )"
hypot_without_test( a, b )
end
alias_method_chain :hypot, :test
module_function :hypot_without_test
module_function :hypot
end
puts Math.hypot( 3, 4 )

=end

Actions #2

Updated by yugui (Yuki Sonoda) almost 15 years ago

  • Assignee set to tadf (tadayoshi funaba)

=begin

=end

Actions #3

Updated by tadf (tadayoshi funaba) over 14 years ago

  • Assignee changed from tadf (tadayoshi funaba) to ko1 (Koichi Sasada)

=begin

=end

Actions #4

Updated by wanabe (_ wanabe) over 14 years ago

  • Status changed from Open to Closed

=begin
fixed by r26255.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0