"David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:Pine.LNX.4.61.0501160831210.8042@wobblini...
Hi --
>
> "David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
> news:Pine.LNX.4.61.0501150344320.20765@wobblini...
>> Hi --
>>
>>
>>>
>>> "Mark Hubbart" <discordantus@gmail.com> schrieb im Newsbeitrag
>>> news:de63abca05011415224d4c29a1@mail.gmail.com...
>>>>
>>>> My only argument against the shortcut syntax is that I can't see
how
>>>> often it could be used, except to simulate static typing. I suspect
>>>> that adding a feature like this would encourage the use of static
>>>> typing in methods.
>>>
>>> Ok, then we need a poll. Or we should dig into Ruby's std lib to
see how
>>> often these methods are called.
>>
>> Not veryFor 1.8.2:
>>
>> $ grep '\.to_str' `find . -name "*.rb"` | grep -v to_string | wc -l
>> 6
>> $ grep '\.to_int' `find . -name "*.rb"` | wc -l
>> 1
>>
>> (It's around 700 for to_s and 300 for to_i.)
>
> Here's my stat of ruby 1.8.2:
>
> $ ruby -e 'Dir["**/*.{h,cC,rb,rw}"].inject(Hash.new(0)){|h,f|
> File.open(f){|io| io.each{|li| li.scan(/to_\w+/){|m|h[m]+=1}}
> };h}.sort.each{|k,v| print k," ",v,"\n"}'
> to_a 193
> to_above 2
> to_access_path 1
> to_addr 3
[...]I would tend to want to match /\.to_\w+/, though I guess some things
have embedded to's (like pixel_to_coords).
But that would not catch cases like def foo() to_s end...
Also, some of the ones
you've found are in comments, such as secs_to_new_year, which is given
in the documentation as an example of something one might write with
DateTime, so it really doesn't have much in common with to_str or
to_int at the language level.
Yeah, it's quite imperfect. I should have used \b to match word
boundaries. Still that would catch comments....
(I do love grepping the lib, I must admit
Apparently. ![]()
Regards
robert
···
On Mon, 17 Jan 2005, Robert Klemme wrote:
>> On Sat, 15 Jan 2005, Robert Klemme wrote: