from irb to .rb? and general question

S

Simon Schuster

say I've been mucking about in irb and want to save some of/all
previous steps into file.rb, is there a way to do this?

also, I've been going through (mostly reading) some tutorials, and am
just slightly confused on how it works when you call up something, a
class or a method definition, and then recall it later.... it doesn't
overwrite what's previously there, just add to it? though in some
cases it seems to overwrite what's already there... but this clearly
isn't the case if I'm making methods in the Array class, for example.
 
B

Ben Bleything

say I've been mucking about in irb and want to save some of/all
previous steps into file.rb, is there a way to do this?

My irb history hack can do this:

http://blog.bleything.net/pages/irb_history

history_write (aliased to hw) takes a filename and a collection of lines
and writes those lines to the file.

Alternately, if you've enabled saving history across sessions, you can
just extract the lines you want from the file it uses for this. Try
~/.irb.history or ~/.irb_history, though I'm sure there are other
variants.
also, I've been going through (mostly reading) some tutorials, and am
just slightly confused on how it works when you call up something, a
class or a method definition, and then recall it later.... it doesn't
overwrite what's previously there, just add to it? though in some
cases it seems to overwrite what's already there... but this clearly
isn't the case if I'm making methods in the Array class, for example.

Sorta! When you re-open a class, you're adding. If you "re-open" a
method, you're overriding.

str = "string"

str.reverse
=> "gnirts"

class String
# additive
def upper_case_it
self.upcase
end

# replace...ative
def reverse
return "reversed!"
end
end

str.upper_case_it
=> STRING

str.reverse
=> "reversed!"


Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top