Getting the most out of Ruby

I write a lot of scripts in Ruby, most are small simple things but some
are growing and getting quite complex.

I came into Ruby from php but with a background of VB, Java and a bit of
C so I’ve picked up some Ruby specific techniques but mostly I’m
probably missing out on some of the cooler stuff that can be done if you
really know what you are doing.

Can anyone recommend any good resources for moving from intermediate up
to really using the power of Ruby. Things like short cuts, essential
gems, issuing method x rather than y because it is more efficient.

Ideally I’d like videos but anything will do.

There are some great tips on here: http://blog.rubybestpractices.com/

I’ve found Refactoring code to be excellent practice in understanding
the “Ruby way” as well. http://ghendry.net/refactor.html

I’m sure the enlightened professionals on here will have plenty to add
as well.

It was watching a video on refactoring from a recent conference that
made me thing I should really put some effort in and improve my skills a
bit.

I’ll have a look at both, thanks.

Robin, If you look at ruby from a polyglot programmer view of the major
paradigms consider this. Ruby is essentially three major paradigms
modeled
after three major programming languages, actually more but lets keep it
simple.

Ruby’s object oriented is modeled after smalltalk; Though it’s marketed
as
python
Ruby’s functional style is modeled after scheme lisp; Ruby programmers
know
the value of everything, but the cost of nothing =)
Ruby’s system programming is modeled after the procedural shell;
Basically
the c programming language, awk, bourne shell, UNIX regular expressions
Et
al. ; This is marketed as Perl( though the %{ literals } came from perl)

Though refactoring (i.e. less tokens == faster execution) is good to
grok
and testing aids the practice and is definitely part of the software
development process it may be also useful to understand Ruby also from
it’s
ancestors which further reseach can be seen from languages and utilities
dating back to early days of computer science in the 1950’s

Good luck and enjoy hacking ruby

~Stu

Stu wrote in post #1112800:

Robin, If you look at ruby from a polyglot programmer view of the major
paradigms consider this. Ruby is essentially three major paradigms
modeled
after three major programming languages, actually more but lets keep it
simple.

Ruby’s object oriented is modeled after smalltalk; Though it’s marketed
as
python
Ruby’s functional style is modeled after scheme lisp; Ruby programmers
know
the value of everything, but the cost of nothing =)
Ruby’s system programming is modeled after the procedural shell;
Basically
the c programming language, awk, bourne shell, UNIX regular expressions
Et
al. ; This is marketed as Perl( though the %{ literals } came from perl)

I really like Ruby’s OO model and it is something that frustrates me
whenever I have to switch to Python as it doesn’t feel quite as nice. I
did some smalltalk at uni so I think that may be why I’m drawn to it.

I do a lot of shell work so the regex stuff comes naturally luckily but
it did take a lot of effort to learn in the first place.

It is the functional style stuff that I’m still getting my head around,
I never really got lisp when they tried to teach it at uni.

Though refactoring (i.e. less tokens == faster execution) is good to
grok
and testing aids the practice and is definitely part of the software
development process it may be also useful to understand Ruby also from
it’s
ancestors which further reseach can be seen from languages and utilities
dating back to early days of computer science in the 1950’s

I’m looking at the refactoring work to try to learn the more “Ruby” ways
to do things rather than initially trying to write faster or tighter
code.

Good luck and enjoy hacking ruby

Thanks

Brandon W. wrote in post #1112804:

Blocks, Lambdas, Closures, Metaprogramming, and Enumerables are the huge
topics. Master them and you’ll see a huge difference.

Got any resources you used to help get your head around all these?

On Tue, Jun 18, 2013 at 9:59 PM, Brandon W.
[email protected]wrote:

The biggest jumping point for me is when I stopped trying to program Ruby
like C# and started programming Ruby like Ruby.

:slight_smile:

Coming from C land you have tendencies towards a lot of imperative
techniques, and Ruby is not solely imperative. Learning the functional side
of Ruby is essential to graduate into advanced topics.

I’d be careful labeling Ruby as “functional”. The only “functional”
about
Ruby is that with lambda you can have anonymous functions which you can
pass around. The core feature of funct

Kind regards

robert

The biggest jumping point for me is when I stopped trying to program
Ruby
like C# and started programming Ruby like Ruby.

Coming from C land you have tendencies towards a lot of imperative
techniques, and Ruby is not solely imperative. Learning the functional
side
of Ruby is essential to graduate into advanced topics.

Blocks, Lambdas, Closures, Metaprogramming, and Enumerables are the huge
topics. Master them and you’ll see a huge difference.

On Wed, Jun 19, 2013 at 10:42 AM, Robert K.
[email protected]wrote:

Coming from C land you have tendencies towards a lot of imperative
techniques, and Ruby is not solely imperative. Learning the functional side
of Ruby is essential to graduate into advanced topics.

I’d be careful labeling Ruby as “functional”. The only “functional” about
Ruby is that with lambda you can have anonymous functions which you can
pass around. The core feature of funct

Sorry, somehow I hit the wrong button and GMail just sent off the email.
What I wanted to say:

I’d be careful labeling Ruby as “functional”. The only “functional”
about
Ruby is that with lambda you can have anonymous functions which you can
pass around and create higher order functions. The core feature of
functional programming for me was always functions without side effects.
And that is not part of Ruby. Of course, you can code lambdas
without
side effects - but the language does not enforce this.

Kind regards

robert

On Tue, Jun 18, 2013 at 6:09 PM, robin wood [email protected]
wrote:
Brandon W. wrote in post #1112804:

Blocks, Lambdas, Closures, Metaprogramming, and Enumerables are the huge
topics. Master them and you’ll see a huge difference.

Got any resources you used to help get your head around all these?

I felt that the book “Meta-Programming Ruby” was very eye opening. It
explains the object model in the first 100 pages. I recommend it based
on
what you’ve said. I rarely push books but that one seems to be written
by
someone who thought through the pedagogical approach of Ruby paradigm
with
everyone coming from different programming backgrounds.

On Wed, Jun 19, 2013 at 3:45 AM, Robert K.
[email protected]wrote:

about Ruby is that with lambda you can have anonymous functions which you
functional programming for me was always functions without side effects.
And that is not part of Ruby. Of course, you can code lambdas without
side effects - but the language does not enforce this.

Kind regards

robert

I agree with you. I am very careful with when I write statements like
that
hence I said “style” as in functional style. I am very used to That
lambda
is important though. It is essentially the primitive of functional
programming( i.e. everything can be build from combination of lambdas)
though it would be not very efficient and is something which may be
explained from a pure “theoretical language” it’s neat to know. Some
people
have ported base scheme implementations to ruby( as those guys port that
language to everything) with just the lambda (once again neat but not
really useful)… bus scheme I believe is one which is the main 7( or 9)
original lisp primitives in 40 lines of code.

Though from an analytical point of view it’s refreshing when the
language
creator explains his motivations when creating ruby:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/179642

There are some others besides lambda and eval in recent ruby releases
such
as both callcc and curry. But lambda the ultimate for those who are into
language creation. I recall a higher order cons enumerators. But it
wasn’t
a pure cons (each_cons maybe). If we had cons we could create our own
literals and further car/cdr would simply be aliases to first and *rest
of
the list which for the most part is basically an array with whitespace
instead of commas for delimitation.

~Stu

Yes that s the book I was recommending. Though not a panacea it’s an
excellent place to begin when your first learning ruby and have some
experience with other programming language concepts. Though it doesn’t
touch shell or system programming it shows the ruby object model and
meta
model and also explains enough functional programming for those who are
new
to that as well. I wouldn’t consider it complete on the pure functional
programming paradigm but it definitely shows you the “Ruby way” of
programming which ultimately ends up with this unique language build on
many paradigms.

Those of you who plan on reading this book I recommend exploring the
concepts with the ruby repl irb, or the fancier one pry, to get the best
experience while manipulating the language within the language. Though
pry
has an wrapper to open the users preferred editor within it’s repl,
since
it’s inspired by emacs/clisp/slime, I used a gem interactive_editor
which
allows does the same thing with irb where you can call vim from inside
irb;
type some ruby code like a method or class definition; then on save it
pushes the code into the running irb repl. It’s a wonderful way to grok
the
language while having fun doing quick experiments and hacks without the
overhead of running a separate terminal or typing require – it supports
other editors and easy to mod. Though I never got around to it I altered
it
to support unix ed and graphical x11 editors which it dynamically picked
up
the locally installed system editors by altering the runtime code from a
apropos/grep call from inside the gem.

I can’t think of any programming language which has the same hack value
as
Ruby. There really are no limitations with ruby. It really is a smart
programming language built by a programmer for programmers.

~Stu

Thanks for all the advice, I’ve bought the book and started looking
through the refactoring guide.

I’ve also found a few interesting tips on here Jesse Storimer

Robin

are you talking about this book??
http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros/dp/1934356476

Eliezer