[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[patch] for ri case sensitivity (was - RE: disable ri case sensit ive

Peña, Botp

7/8/2005 9:20:00 AM

##> Arg, i'm in windows and i cannot even find ri.rb. I guess it
##is not written
##> in ruby, no?
##
##I guess you already found this, but it's called ri.bat which is just a
##wrapper for ri. And the source for ri is in lib\ruby\1.8\rdoc\ri.
##
#
#you guess wrong, i'm dumber than you think :-)
#
#Thanks for the info, Cris. I'll check..
#
#kind regards -botp
#


ok, i got a hack.

pardon me if it's too elementary or buggy or what, but hey, it works great
for me and i have lesser worry on my casing/typing :-)

btw, is there a proper_case in ruby? like "test".proper_case => "Test"

patch follows
---------------------------

C:\ruby\lib\ruby\1.8\rdoc\ri>diff ri_util.rb ri_util.rb.orig
3,9d2
< # pardon me with this, but i cannot find a proper_case string fxn
< class String
< def proper_case
< self[0,1].upcase + (self[1..-1]? self[1..-1].downcase : "")
< end
< end
<
40,59c33
<
< # all programmers are lazy
< # so, let us take care of the casing thing
<
< if tokens.size < 2
< # it's a word; check if the casing is garbled
< t = tokens[0]
< if (t != t.downcase) and
< (t != t.proper_case)
< t.downcase! # it's garbled; defaulting to downcase (as method)
< end
< else
< # propercase them all
< tokens.map!{ |x| x.proper_case }
< # methods should be downcased however
< if tokens[-2] =~ /\.|#|/
< tokens[-1] = tokens[-1].downcase
< end
< end
<
---
>
64a39
>
67d41
<
101,102d74
<
<
104d75



3 Answers

Yukihiro Matsumoto

7/8/2005 9:28:00 AM

0

Hi,

In message "Re: [patch] for ri case sensitivity (was - RE: disable ri case sensit ive)"
on Fri, 8 Jul 2005 18:20:26 +0900, "Peña, Botp" <botp@delmonte-phil.com> writes:

|ok, i got a hack.

|patch follows

Use unified diff (diff -u), or at least context diff (diff -c).

matz.


Gavin Kistner

7/8/2005 12:41:00 PM

0

On Jul 8, 2005, at 3:20 AM, Peña, Botp wrote:
> btw, is there a proper_case in ruby? like "test".proper_case => "Test"

> cat case_test.rb
class String
def titlecase!
self.downcase!
self.gsub!( /\b\w/ ){ |t| t.upcase }
self
end
def titlecase
self.dup.titlecase!
end
end
str = "hElLo WoRlD"
case_methods = %w| downcase upcase capitalize titlecase |
case_methods.each{ |method_name|
puts "%s.%-10s #=> %s" % [ str.inspect, method_name, str.send
(method_name) ]
}

> ruby case_test.rb
"hElLo WoRlD".downcase #=> hello world
"hElLo WoRlD".upcase #=> HELLO WORLD
"hElLo WoRlD".capitalize #=> Hello world
"hElLo WoRlD".titlecase #=> Hello World

nobu.nokada

7/9/2005 3:11:00 AM

0

Hi,

At Fri, 8 Jul 2005 18:20:26 +0900,
Peña, Botp wrote in [ruby-talk:147544]:
> pardon me if it's too elementary or buggy or what, but hey, it works great
> for me and i have lesser worry on my casing/typing :-)

It seems not to work with a multi-worded class name, e.g.,
SystemCallError#errno.

$ ./ruby bin/ri -T systemcall#errno
Nothing known about systemcall#errno

Another patch.


Index: lib/rdoc/ri/ri_cache.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/rdoc/ri/ri_cache.rb,v
retrieving revision 1.8
diff -U2 -p -w -r1.8 ri_cache.rb
--- lib/rdoc/ri/ri_cache.rb 30 Aug 2004 14:20:57 -0000 1.8
+++ lib/rdoc/ri/ri_cache.rb 9 Jul 2005 02:55:05 -0000
@@ -33,5 +33,5 @@ module RI

# convert from external to internal form, and
- # extract the instance/class flag
+ # extract the "instance/class" flag

if name =~ /^(.*?)-(c|i).yaml$/
@@ -62,5 +62,10 @@ module RI

def contained_modules_matching(name)
- @inferior_classes.find_all {|c| c.name[name]}
+ mods = @inferior_classes.find_all {|c| c.name[name]}
+ if mods.empty?
+ name = name.downcase
+ mods = @inferior_classes.find_all {|c| c.name.downcase[name]}
+ end
+ mods
end

@@ -71,5 +76,6 @@ module RI
# Return an exact match to a particular name
def contained_class_named(name)
- @inferior_classes.find {|c| c.name == name}
+ @inferior_classes.find {|c| c.name == name} or
+ @inferior_classes.find {|c| c.name.casecmp(name).zero?}
end

Index: lib/rdoc/ri/ri_util.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/rdoc/ri/ri_util.rb,v
retrieving revision 1.5
diff -U2 -p -w -r1.5 ri_util.rb
--- lib/rdoc/ri/ri_util.rb 24 Mar 2004 18:59:10 -0000 1.5
+++ lib/rdoc/ri/ri_util.rb 9 Jul 2005 02:55:50 -0000
@@ -30,9 +30,9 @@ class NameDescriptor
separator = nil

- tokens = arg.split(/(\.|::|#)/)
+ tokens = arg.split(/(\.|::|\#)/)

# Skip leading '::', '#' or '.', but remember it might
# be a method name qualifier
- separator = tokens.shift if tokens[0] =~ /^(\.|::|#)/
+ separator = tokens.shift if /^(\.|::|\#)/ =~ tokens[0]

# Skip leading '::', but remember we potentially have an inst
@@ -40,5 +40,5 @@ class NameDescriptor
# leading stuff must be class names

- while tokens[0] =~ /^[A-Z]/
+ while /^[A-Z]/ =~ tokens[0] or /::|\#/ =~ tokens[1]
@class_names << tokens.shift
unless tokens.empty?


--
Nobu Nakada