The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Shortening Perl with Ruby

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Shortening Perl with Ruby Posted: May 9, 2005 9:50 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Shortening Perl with Ruby
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
As I'm working on porting the 43 page Worksheet.pm Perl module (and that's in a 10pt font), I've been able to cut down much of the overall length of the code by leveraging (eww) the power of Ruby.

Here's what I would consider a typical snippet of Perl code from Worksheet.pm:
sub center_horizontally {

    my $self = shift;

    if (defined $_[0]) {
        $self->{_hcenter} = $_[0];
    }
    else {
        $self->{_hcenter} = 1;
    }
}

And here's the Ruby translation:
def center_horizontally(val = 1)
   @hcenter = val
end

The ability to assign default values in an argument list, plus an implicit self generally means I can greatly reduce line (and character) count, yet retain readability. I can also eliminate all of the getters and setters with a simple attr_accessor call.

Nice, eh?

Read: Shortening Perl with Ruby

Topic: I’m tuned to Virgin Radio Classic Rock Previous Topic   Next Topic Topic: Freak printer incident

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use