diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-28 13:24:55 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-28 13:24:55 +0000 |
commit | 7996581a82836fc7635bba858b946c67edc56bba (patch) | |
tree | efb716ea400b5d5c4e9b6cc33ad9ff38d6e230ea /ext | |
parent | 4b8f2ed7cc0fb9623ba7582c4576fa37e3620737 (diff) | |
download | ruby-7996581a82836fc7635bba858b946c67edc56bba.tar.gz |
* 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
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pathname/lib/pathname.rb | 12 | ||||
-rw-r--r-- | ext/pathname/pathname.c | 16 |
2 files changed, 16 insertions, 12 deletions
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); } |