Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Thousands of words on Ruby
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  17 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tim Bray  
View profile  
 More options Sep 6 2006, 5:40 pm
From: Tim Bray <tb...@textuality.com>
Date: Thu, 7 Sep 2006 06:40:23 +0900
Local: Wed, Sep 6 2006 5:40 pm
Subject: Thousands of words on Ruby
I just finished a much-too-long series of essays on Ruby from a whole  
bunch of angles, some here might enjoy it: http://www.tbray.org/
ongoing/When/200x/2006/08/17/JRuby

   -Tim


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 7 2006, 10:22 am
From: James Edward Gray II <ja...@grayproductions.net>
Date: Thu, 7 Sep 2006 23:22:25 +0900
Local: Thurs, Sep 7 2006 10:22 am
Subject: Re: Thousands of words on Ruby
On Sep 6, 2006, at 4:40 PM, Tim Bray wrote:

> I just finished a much-too-long series of essays on Ruby from a  
> whole bunch of angles, some here might enjoy it: http://
> www.tbray.org/ongoing/When/200x/2006/08/17/JRuby

I found it interesting reading.  It really felt like early  
explorations of the language.  Here are some random thoughts I had  
while reading:

* There are multiple places to get XML escaping from the standard  
library, but since you are familiar with REXML I'll recommend:  
REXML::Text.normalize("Some &amp; text &lt; foo &gt; \" bar")

* I really like that Ruby leaves the power to decide where to store  
code in our hands.  Just to give random example of how this is cool,  
I purposefully keep my FasterCSV library in one long source file.  
When I'm working on some project and need to work with CSV, I drop  
the file in vendor/ and I'm all set.

* http://blog.grayproductions.net/articles/2006/06/13/do-i-need-these-
parenthese

* A DSL is slightly more than method calls without parentheses.  The  
idea is to adapt your language to the problem domain, so the solution  
is very naturally expressed in the language of the problem.

* For markup generation:  have you tried Builder?

* The "helper methods" referred to in the quoted Markaby  
documentation are a Railsism.  I suspect that's why you had trouble  
understanding the quote.

* I mean this in the nicest possible way, of course, but you're dead  
wrong about that IDE thing.  ;)  I have a solution for each point you  
listed in TextMate and I would be shocked if you can't do similar  
things in emacs (the editor I believe you are using).  I'm happy to  
post them, if there's interest.

* I'm looking forward to your Unicode talk.  Just remember to start  
it with, "Ruby supports Unicode today."  ;)  It really, really bugs  
me that everyone claims Ruby has no Unicode support.  Don't be like  
them.  As long as you get off to a good start like that, I'll be very  
interested in the rest of your talk and I won't lead the lynch mod  
your essay hints at.

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 7 2006, 12:12 pm
From: James Edward Gray II <ja...@grayproductions.net>
Date: Fri, 8 Sep 2006 01:12:47 +0900
Local: Thurs, Sep 7 2006 12:12 pm
Subject: Re: Thousands of words on Ruby
On Sep 7, 2006, at 9:22 AM, James Edward Gray II wrote:

> Here are some random thoughts I had while reading:

One more that came to me later:

*  I like XPath, but some libraries do a neat job of allowing you to  
tree walk with Ruby.  See Rubyful Soup and Hpricot for a couple of  
great examples.

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Molitor, Stephen L  
View profile  
 More options Sep 7 2006, 3:11 pm
From: "Molitor, Stephen L" <Stephen.L.Moli...@erac.com>
Date: Fri, 8 Sep 2006 04:11:49 +0900
Local: Thurs, Sep 7 2006 3:11 pm
Subject: Re: Thousands of words on Ruby
James,

What do you do for 'rename method' in TextMate?  I'm aware of the search
and replace in file feature but I was wondering if there was something
better.

Nice write-up by the way.  Ruby IDEs might not do all that Eclipse or
NetBeans does for Java, but they're not as primitive as Tim made them
out to be!  I was also surprised that he hadn't tried Builder.

Steve


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 7 2006, 4:11 pm
From: James Edward Gray II <ja...@grayproductions.net>
Date: Fri, 8 Sep 2006 05:11:13 +0900
Local: Thurs, Sep 7 2006 4:11 pm
Subject: Re: Thousands of words on Ruby
On Sep 7, 2006, at 2:11 PM, Molitor, Stephen L wrote:

> What do you do for 'rename method' in TextMate?  I'm aware of the  
> search
> and replace in file feature but I was wondering if there was something
> better.

First, let me admit this is the point I have the least ideal solution  
for and I am interested in a Ruby Refactoring library I can wrap in  
TextMate commands.  Remember though, knowing everything about a Ruby  
script is all but impossible until runtime.  Given that, such a  
library would likely function off of heuristics, and that's about as  
accurate as...

I use TextMate's Find in Project with a hand rolled regular  
expression.  For your example of a method call I might try something  
like:

      Find:  (\.|^[ \t]*)method_name\b
   Replace:  $1new_name

I can sometimes refine that a little depending on my knowledge of the  
project at hand.  I always do a Find first, reality-check the  
matches, then Replace All.  I find this works a very high percentage  
of the time, though I do make mistakes, of course.

Here are my solutions to the other points:

>       There should be a background parser running all the time so  
> that you always know if you have syntax errors and can jump to them  
> with one click; it is so totally a waste of time for me to save,  
> then try to run, a file that the computer is in a position to know  
> won’t work.

I built a TextMate command scoped to Ruby source with a key  
equivalent of apple-S that takes the document as input and asks TM to  
save the current document when triggered.  (This essentially  
overrides Save in Ruby files, performs the Save, and allows me to  
hook in additional functionality.

I feed the document to `ruby -c`.  If it checks out, I display a  
Syntax OK tool tip (default output for this command).  If errors are  
found, I use the exit_codes.rb support library that ships with  
TextMate to switch the output to HTML and display hyperlinked-back-to-
the-source error messages.

This command is an example in my upcoming book:

   http://www.pragmaticprogrammer.com/titles/textmate/index.html

>       I shouldn’t have to type the names of well-known methods,  
> like File.new or (anything).each, or type in closing parentheses or  
> the keyword end, or fill in more than a couple of characters of  
> begin/rescue/ensure structures; it is never correct for a human to  
> hit keys when a computer, in principle, could provide the input.

One word:  snippets.

TextMate ships with all the snippets I have written for Ruby and then  
some.

>       I should never have to scroll much; IDEs go to a lot of  
> trouble to make it trivial to jump from wherever to the source for  
> the method being called, or its docs, or the next compile error or  
> breakpoint, or variable declaration, or whatever. Scrolling back  
> and forth in a source-code file is just stupid.

Apple-T to zoom to the needed file, shift-apple-T to zoom to the  
needed method.  Once you get use to how it matches names you can go  
anywhere in an instant:

   1.  apple-T
   2.  bit-return (takes me to test/functional/beta_invite_test.rb)
   3.  shift-apple-T
   4.  teir-return (takes me to test_email_is_required)

>       Unit testing should be part of the infrastructure. To create  
> a test, or run a test, or look at test results, you shouldn’t have  
> to hit more than one keystroke.

Apple-R to run a test file, or shift-apple-R to run just the current  
test.    Use zentest to auto-generate the tests (you can wrap that in  
a TextMate command with about three lines of Ruby, if you like).

Hope this helps.

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Molitor, Stephen L  
View profile  
 More options Sep 7 2006, 4:59 pm
From: "Molitor, Stephen L" <Stephen.L.Moli...@erac.com>
Date: Fri, 8 Sep 2006 05:59:35 +0900
Local: Thurs, Sep 7 2006 4:59 pm
Subject: Re: Thousands of words on Ruby
Fantastic, thanks.  One more minor question:  what is 'bit-return' and
'teir-return'.

Steve


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gavin Kistner  
View profile  
 More options Sep 7 2006, 5:17 pm
From: "Gavin Kistner" <gavin.kist...@anark.com>
Date: Fri, 8 Sep 2006 06:17:54 +0900
Local: Thurs, Sep 7 2006 5:17 pm
Subject: Re: Thousands of words on Ruby
From: Molitor, Stephen L [mailto:Stephen.L.Moli...@erac.com]

> Fantastic, thanks.  One more minor question:  what is 'bit-return' and
> 'teir-return'.

I think that 'bit-return' means
"typing in the letters 'b', 'i', 't', and pressing return".

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 7 2006, 5:23 pm
From: James Edward Gray II <ja...@grayproductions.net>
Date: Fri, 8 Sep 2006 06:23:26 +0900
Local: Thurs, Sep 7 2006 5:23 pm
Subject: Re: Thousands of words on Ruby
On Sep 7, 2006, at 3:59 PM, Molitor, Stephen L wrote:

> Fantastic, thanks.  One more minor question:  what is 'bit-return' and
> 'teir-return'.

b-i-t-return and t-e-i-r-return.

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Devin Mullins  
View profile  
 More options Sep 8 2006, 12:37 am
From: Devin Mullins <twif...@comcast.net>
Date: Fri, 8 Sep 2006 13:37:31 +0900
Local: Fri, Sep 8 2006 12:37 am
Subject: Re: Thousands of words on Ruby

> I built a TextMate command scoped to Ruby source with a key  equivalent
> of apple-S that takes the document as input and asks TM to  save the
> current document when triggered.  (This essentially  overrides Save in
> Ruby files, performs the Save, and allows me to  hook in additional
> functionality.

> <snip>

> This command is an example in my upcoming book:

>   http://www.pragmaticprogrammer.com/titles/textmate/index.html

Err, oh. I take it that means it'd be too much to ask how you command TM
to save?

Devin
(what's the emoticon for "sad puppy face"?)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 8 2006, 8:47 am
From: James Edward Gray II <ja...@grayproductions.net>
Date: Fri, 8 Sep 2006 21:47:12 +0900
Local: Fri, Sep 8 2006 8:47 am
Subject: Re: Thousands of words on Ruby
On Sep 7, 2006, at 11:37 PM, Devin Mullins wrote:

>> I built a TextMate command scoped to Ruby source with a key  
>> equivalent of apple-S that takes the document as input and asks TM  
>> to  save the current document when triggered.  (This essentially  
>> overrides Save in Ruby files, performs the Save, and allows me to  
>> hook in additional functionality.
>> <snip>
>> This command is an example in my upcoming book:
>>   http://www.pragmaticprogrammer.com/titles/textmate/index.html

> Err, oh. I take it that means it'd be too much to ask how you  
> command TM to save?

The "Save" dropdown menu at the top of the Bundle Editor when you are  
editing a command.  ;)

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Molitor, Stephen L  
View profile  
 More options Sep 8 2006, 11:02 am
From: "Molitor, Stephen L" <Stephen.L.Moli...@erac.com>
Date: Sat, 9 Sep 2006 00:02:48 +0900
Local: Fri, Sep 8 2006 11:02 am
Subject: Re: Thousands of words on Ruby
Doh!  And here I was looking for something more exciting and esoteric.

Steve


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Sanheim  
View profile  
 More options Sep 8 2006, 1:00 pm
From: "Rob Sanheim" <rsanh...@gmail.com>
Date: Sat, 9 Sep 2006 02:00:56 +0900
Local: Fri, Sep 8 2006 1:00 pm
Subject: Re: Thousands of words on Ruby
On 9/6/06, Tim Bray <tb...@textuality.com> wrote:

> I just finished a much-too-long series of essays on Ruby from a whole
> bunch of angles, some here might enjoy it: http://www.tbray.org/
> ongoing/When/200x/2006/08/17/JRuby

>    -Tim

I would highly recommend autotest, which is part of ZenTest, to take
tdd to the next level.  Autotest has your desired "one keystroke"
beat, as its zero keystrokes to run any test.  It monitors your files
and automatically runs tests when it sees the tests or related files
changed.

I'm using it for rails work and its great.  There are some minor
annoyances, such as not picking up integration tests or tests in /lib
correctly right now, but its not very hard to hack stuff into the
source.

- rob

--
http://www.robsanheim.com
http://www.seekingalpha.com
http://www.ajaxian.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Young  
View profile  
 More options Sep 9 2006, 10:41 am
From: Alex Young <a...@blackkettle.org>
Date: Sat, 9 Sep 2006 23:41:18 +0900
Local: Sat, Sep 9 2006 10:41 am
Subject: Re: Thousands of words on Ruby
James Edward Gray II wrote:

> On Sep 7, 2006, at 2:11 PM, Molitor, Stephen L wrote:

>> What do you do for 'rename method' in TextMate?  I'm aware of the search
>> and replace in file feature but I was wondering if there was something
>> better.

> First, let me admit this is the point I have the least ideal solution
> for and I am interested in a Ruby Refactoring library I can wrap in
> TextMate commands.  Remember though, knowing everything about a Ruby
> script is all but impossible until runtime.  

Brainstorm just happened, so bear with me - this is straight off the top
  of my head, and may be stupid:

Ok, so it's a real bodge to try to rename a method before runtime.  What
happens if we annotate the method to be renamed the next time it's run?
  We could run the script in question under an environment not totally
unlike xmp.  The first thing it would do is alter the source file
according to the annotation.  It would then add an appropriate
method_missing to Object to do a rename in the original source file
whenever the method was called, and then load() the file.

Good idea?  Worth trying?  Hideously flawed?

--
Alex


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 9 2006, 11:19 am
From: James Edward Gray II <ja...@grayproductions.net>
Date: Sun, 10 Sep 2006 00:19:39 +0900
Local: Sat, Sep 9 2006 11:19 am
Subject: Re: Thousands of words on Ruby
On Sep 9, 2006, at 9:41 AM, Alex Young wrote:

> Ok, so it's a real bodge to try to rename a method before runtime.  
> What happens if we annotate the method to be renamed the next time  
> it's run?  We could run the script in question under an environment  
> not totally unlike xmp.  The first thing it would do is alter the  
> source file according to the annotation.  It would then add an  
> appropriate method_missing to Object to do a rename in the original  
> source file whenever the method was called, and then load() the file.

And what happens if the execution never calls the given method, for  
whatever reason, or only reaches some of the places it is used?

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Young  
View profile  
 More options Sep 9 2006, 11:33 am
From: Alex Young <a...@blackkettle.org>
Date: Sun, 10 Sep 2006 00:33:26 +0900
Local: Sat, Sep 9 2006 11:33 am
Subject: Re: Thousands of words on Ruby
James Edward Gray II wrote:
> On Sep 9, 2006, at 9:41 AM, Alex Young wrote:

>> Ok, so it's a real bodge to try to rename a method before runtime.  
>> What happens if we annotate the method to be renamed the next time
>> it's run?  We could run the script in question under an environment
>> not totally unlike xmp.  The first thing it would do is alter the
>> source file according to the annotation.  It would then add an
>> appropriate method_missing to Object to do a rename in the original
>> source file whenever the method was called, and then load() the file.

> And what happens if the execution never calls the given method, for
> whatever reason, or only reaches some of the places it is used?

That's why you run your test suite through it.  You do have 100% line
coverage, right?  :-)

--
Alex


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Edward Gray II  
View profile  
 More options Sep 9 2006, 11:41 am
From: James Edward Gray II <ja...@grayproductions.net>
Date: Sun, 10 Sep 2006 00:41:34 +0900
Local: Sat, Sep 9 2006 11:41 am
Subject: Re: Thousands of words on Ruby
On Sep 9, 2006, at 10:33 AM, Alex Young wrote:

> James Edward Gray II wrote:
>> On Sep 9, 2006, at 9:41 AM, Alex Young wrote:
>>> Ok, so it's a real bodge to try to rename a method before  
>>> runtime.  What happens if we annotate the method to be renamed  
>>> the next time it's run?  We could run the script in question  
>>> under an environment not totally unlike xmp.  The first thing it  
>>> would do is alter the source file according to the annotation.  
>>> It would then add an appropriate method_missing to Object to do a  
>>> rename in the original source file whenever the method was  
>>> called, and then load() the file.
>> And what happens if the execution never calls the given method,  
>> for whatever reason, or only reaches some of the places it is used?
> That's why you run your test suite through it.  You do have 100%  
> line coverage, right?  :-)

Well it's a clever idea.  Show us the prototype.  ;)

James Edward Gray II


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Young  
View profile  
 More options Sep 9 2006, 1:44 pm
From: Alex Young <a...@blackkettle.org>
Date: Sun, 10 Sep 2006 02:44:07 +0900
Local: Sat, Sep 9 2006 1:44 pm
Subject: Re: Thousands of words on Ruby
James Edward Gray II wrote:

Well, you asked for it :-)  The usual provisos for prototype code apply:

$ cat rename_method.rb
$obj_replacement_table = {}
class Object
   def method_missing(sym, *args, &block)
     if $obj_replacement_table.has_key? sym.to_s
       filename, line_num = caller[0].split(':')[0,2]
       l = line_num.to_i - 1
       line_arr = File.readlines(filename)
       line_arr[l] = line_arr[l].sub(sym.to_s,
$obj_replacement_table[sym.to_s])
       File.open(filename, 'wb'){|f| f.write line_arr}
       self.send($obj_replacement_table[sym.to_s].to_sym, *args, &block)
     end
   end
end

def process_file(filename)
   line_arr = File.readlines(filename)
   line_arr.each_with_index do |line,i|
     if line.chomp =~ /(\s+)def (\w+)(.*)#\s*becomes\s+(\w+)/
       line_arr[i] = "#{$1}def #{$4}#{$3}# was #{$2}\n"
       $obj_replacement_table[$2] = $4
     end
   end
   File.open(filename, 'wb'){|f| f.write line_arr }
end

process_file(ARGV[0])
load(ARGV[0])

$ cat subject.rb
class TestClass
   def my_method(foo) # becomes my_new_method
     puts foo
   end
end

def meth_calling_renamed(t)
   t.my_method('Ok2')
end

t = TestClass.new
t.my_method('Ok1')
meth_calling_renamed(t)

$ ruby rename_method.rb subject.rb
Ok1
Ok2

$ cat subject.rb
class TestClass
   def my_new_method(foo) # was my_method
     puts foo
   end
end

def meth_calling_renamed(t)
   t.my_new_method('Ok2')
end

t = TestClass.new
t.my_new_method('Ok1')
meth_calling_renamed(t)

There's a *lot* of scope for improvement in there, obviously, but that's
the general idea.

--
Alex


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google