summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/pathname/lib/pathname.rb12
-rw-r--r--ext/pathname/pathname.c16
3 files changed, 21 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index b50c926e83..7e106d1ece 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jul 28 22:23:59 2010 Tanaka Akira <akr@fsij.org>
+
+ * ext/pathname/pathname.c (path_eq): Pathname#{==,===,eql?} translated
+ from pathname.rb.
+
Wed Jul 28 19:37:33 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub (config.h): VC6 or later have stddef.h.
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 (<tt>foo.txt</tt> and <tt>./foo.txt</tt>)
- # 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 (<tt>foo.txt</tt> and <tt>./foo.txt</tt>)
+ * 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);
}