From 7996581a82836fc7635bba858b946c67edc56bba Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 28 Jul 2010 13:24:55 +0000 Subject: * ext/pathname/pathname.c (path_eq): Pathname#{==,===,eql?} translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/pathname/lib/pathname.rb | 12 ------------ ext/pathname/pathname.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'ext') diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 139b8e3662..8abbd667e5 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -208,18 +208,6 @@ class Pathname # :startdoc: - # - # Compare this pathname with +other+. The comparison is string-based. - # Be aware that two different paths (foo.txt and ./foo.txt) - # can refer to the same file. - # - def ==(other) - return false unless Pathname === other - other.to_s == @path - end - alias === == - alias eql? == - # Provides for comparing pathnames, case-sensitively. def <=>(other) return nil unless Pathname === other diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 2d3a173f5b..17256fd81d 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -69,6 +69,19 @@ path_untaint(VALUE self) return self; } +/* + * Compare this pathname with +other+. The comparison is string-based. + * Be aware that two different paths (foo.txt and ./foo.txt) + * can refer to the same file. + */ +static VALUE +path_eq(VALUE self, VALUE other) +{ + if (!rb_obj_is_kind_of(other, rb_cPathname)) + return Qfalse; + return rb_str_equal(get_strpath(self), get_strpath(other)); +} + void Init_pathname() { @@ -80,4 +93,7 @@ Init_pathname() rb_define_method(rb_cPathname, "freeze", path_freeze, 0); rb_define_method(rb_cPathname, "taint", path_taint, 0); rb_define_method(rb_cPathname, "untaint", path_untaint, 0); + rb_define_method(rb_cPathname, "==", path_eq, 1); + rb_define_method(rb_cPathname, "===", path_eq, 1); + rb_define_method(rb_cPathname, "eql?", path_eq, 1); } -- cgit v1.2.3