<ccooke>
nakilon: Technically, I suspect that it would have been by way of perl. Ruby picks up a lot of inspiration from perl, after all.
<ccooke>
(of course, perl did not originate them, but there's a chain of inheritance here :-)
hellstabber has quit [Remote host closed the connection]
<weaksauce>
I think perl had them because of awk and awk probably started the chain
<weaksauce>
i imagine awk started it at least since it makes the most sense for that program
graywolf has joined #ruby
<ccooke>
I believe they predate awk
<wnd>
there's algol with BEGIN and END
<ccooke>
yeah
<ccooke>
I was just trying to check if algol had them, but it is late and my searching is clearly bad)
<ccooke>
(If I'm reading correclty, Algol has a compile time block delimited by BEGIN...END. It does not have a BEGIN and END block that execute before or after the rest of the code respectively
<ccooke>
If I'm reading this correctly, of course)
<ccooke>
(well, looks like perl definitely got BEGIN/END from awk; awk had them pre perl 1.0, perl 1.0 has them and explicitly is announced as a replacemrnt for sed/awk/shell)
<ccooke>
(... I should go sleep and stop nerdsniping myself)
<weaksauce>
oh yeah i meant them in the way ruby uses them not the way other programming languages use them
<weaksauce>
begin end is in many languages to denote a block
graywolf has quit [Quit: WeeChat 3.3]
<John_Ivan>
weaksauce, does ruby support macro redefinition?
<John_Ivan>
e.g something similar to "#define keyword my_own"
<weaksauce>
it supports a lot of metaprogramming
<weaksauce>
it's... very flexible
<John_Ivan>
I like the sound of that :>
<weaksauce>
method_missing, const_missing, open classes
<weaksauce>
dynamic dispatch
<weaksauce>
method definition on the fly
<weaksauce>
alias is a keyword you can use to redefine methods
<John_Ivan>
weaksauce, fucking sweet!
<weaksauce>
alias_method is another with slightly similar semantics
<weaksauce>
if you just want to overwrite a method you can just redefine it
<weaksauce>
class String; def to_s "hello"; end; end
<John_Ivan>
weaksauce, so what would be a way for me to, say, introduce { } on if statements, methods, etc instead of "end"?
<John_Ivan>
e.g if (), while (), def mymethod() {}, etc.
<John_Ivan>
uh
<John_Ivan>
if {}** while {}**
<weaksauce>
that's probably one of the few things that is not possible
<weaksauce>
you can pass {} to methods
<John_Ivan>
awh. pity.
<weaksauce>
and it is a block
<weaksauce>
that you can call inside it
<weaksauce>
like each {|x| puts x }
<weaksauce>
that's basically just an anonymous function that gets passed into the function either explicitly or implicitly depending
<John_Ivan>
hm
<John_Ivan>
yeah. gotcha
<John_Ivan>
I mean
<weaksauce>
def each(&theblock) theblock.call() end
<John_Ivan>
I don't mind the end. I'm actually relieved it's there. in python there's NOTHING
<John_Ivan>
but between having something there and nothing, I prefer braces
<John_Ivan>
:P
<weaksauce>
or def each; yield(something); end
<weaksauce>
that is the difference
<weaksauce>
yeah since blocks are so common in ruby the do end and { } syntax is all over the place and you can't really use it for control flow like you want
<John_Ivan>
weaksauce, no worries.
geewiz has joined #ruby
<John_Ivan>
weaksauce, do you use anything other than IRC? discord for example?
<gr33n7007h>
John_Ivan: you could do something like this: def iff(cond, &b) b.call if cond end; iff ( 1 == 1 ) { puts :yay }
szkl has quit [Quit: Connection closed for inactivity]
arkantos has quit [Quit: Connection closed for inactivity]
hololeap has joined #ruby
kapil has joined #ruby
edrx has joined #ruby
<edrx>
ppl, how do I get a REPL for ruby without the fancy colors of irb?
<edrx>
irb works well in the way of using Ruby from Emacs described in these slides - http://angg.twu.net/LATEX/2021emacsconf.pdf - _on recent versions of Emacs_, but its terminal control sequences confuse older versions of Emacs...
oxfuxxx has quit [Quit: Raccoon's not another IRC transgenre wannabe who can't fap at the dead american dream, fhackerz]
<bobdobbs`>
I'm trying to check if a directory exists. I get different results from Dir.exist? depending if I'm running it from a file or running it from irb. This is my file: http://pastie.org/p/0BHHZ3evaTr4jHzQAkJRRc
<bobdobbs`>
If I pass in the name of a directory to the function Dir.exists? in that script, I get "false". But if I pass the exact same value into Dir.exist? in irb, I get 'true'.
<bobdobbs`>
Also in irb, the following line returns true: b = Dir.exist?('[pathname]')
perrierjouet has quit [Quit: WeeChat 3.3]
edrx has left #ruby [Killed buffer]
perrierjouet has joined #ruby
perrierjouet has quit [Client Quit]
perrierjouet has joined #ruby
oxfuxxx has joined #ruby
teclator has joined #ruby
oxfuxxx has quit [Quit: Raccoon's not another IRC transgenre wannabe who can't fap at the dead american dream, fhackerz]
oxfuxxx has joined #ruby
oxfuxxx has quit [Remote host closed the connection]
oxfuxxx has joined #ruby
oxfuxxx has quit [Remote host closed the connection]
oxfuxxx has joined #ruby
oxfuxxx has quit [Client Quit]
<weaksauce>
bobdobbs` probably the newline thing try chomp
<weaksauce>
or you can use strip on the gets
oxfuxxx has joined #ruby
oxfuxxx has quit [Remote host closed the connection]
oxfuxxx has joined #ruby
oxfuxxx has quit [Quit: Raccoon's not another IRC transgenre wannabe who can't fap at the dead american dream, fhackerz]
oxfuxxx has joined #ruby
oxfuxxx has quit [Remote host closed the connection]
gproto23 has joined #ruby
_ht has joined #ruby
<gproto23>
hey folks. i need a module for building complex pipelines in ruby
robotmay has quit [Quit: No Ping reply in 180 seconds.]
robotmay has joined #ruby
<John_Ivan>
gr33n7007h, I guess :)
<John_Ivan>
weaksauce, morning.
<John_Ivan>
I mean
<John_Ivan>
'top o' tha mornin' to yah me ol bud
lim has joined #ruby
lim has quit [Remote host closed the connection]
lim has joined #ruby
lim has quit [Remote host closed the connection]
lim has joined #ruby
lim has quit [Remote host closed the connection]
MeowcatWoofWoofF has quit [Quit: Client limit exceeded: 20000]
bit4bit has joined #ruby
casionaut has joined #ruby
infernix has quit [Ping timeout: 268 seconds]
michigan has joined #ruby
casionaut has quit [Quit: bye]
Guest7555 has joined #ruby
bit4bit has quit [Ping timeout: 256 seconds]
bluesh55 has joined #ruby
bluesh55 has left #ruby [WeeChat 3.3]
alain has joined #ruby
bluesh55 has joined #ruby
bluesh55 has left #ruby [WeeChat 3.3]
Guest7555 has left #ruby [#ruby]
catsh has joined #ruby
roadie has joined #ruby
catsh has quit [Quit: WeeChat 3.3]
catsh has joined #ruby
catsh has quit [Client Quit]
hellstabber has joined #ruby
roadie has quit [Ping timeout: 268 seconds]
roadie has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
roadie has joined #ruby
roadie has quit [Remote host closed the connection]
roadie has joined #ruby
roadie has quit [Ping timeout: 245 seconds]
roadie has joined #ruby
timkaechele has joined #ruby
timkaechele1 has joined #ruby
timkaechele has quit [Ping timeout: 240 seconds]
bit4bit has joined #ruby
hellstabber has quit [Read error: Connection reset by peer]
graemefawcett has quit [Ping timeout: 268 seconds]
<bobdobbs`>
In a command-line script, I want to present the user with a set of options. I then want to store the options selected by the user. I imagine the script presenting something like this to the user: http://pastie.org/p/0fyYIOhvhJzaCeCSsDQ0wR
MeowcatWoofWoofF has joined #ruby
<bobdobbs`>
How can I do this?
ur5us_ has joined #ruby
graemefawcett has joined #ruby
gproto23 has quit [Remote host closed the connection]
<bobdobbs`>
adam12: thank you! I'll experiment with one or both of those
<adam12>
bobdobbs`: I use tty-prompt in many projects. I think I've used tty-config in one? project. They both work well.
<leftylink>
I think that in many instructional texts it is common to make a number guessing game to demonstrate interaction with the user... so perhaps a basic thing to search for might be "ruby guessing game"
<michigan>
I remember wanting to rewrite all my Bash scripts in Ruby, but gave up when I saw how messy it al looked compared to regular Ruby scripts
<michigan>
Ended up just rewriting them in Zsh instead (file renaming, find-and-replace etc.) -- a *lot* cleaner than Bash at least
_ht has quit [Remote host closed the connection]
<leftylink>
what was that thing that went "never use X when Y can do the trick" "never use Y when Z can do it"
teclator has quit [Remote host closed the connection]
<bobdobbs`>
I'm building a script. I've got a kind of "master stub" in a parent directory and tests in a subdirectory. In the parent directory I've got a Gemfile that pulls in a couple of gems to the project. How can I make those gems accessible to my tests in the child directory?
ur5us_ has joined #ruby
<bobdobbs`>
oh, actually I might have deeper problems. Even the script in the parent directory can't access the gems
<bobdobbs`>
It seems to indicate a conflict between available version of a gem. So I deleted all the rubygems available to the version of ruby I'm using, and reinstalled the tty gem
<bobdobbs`>
But when I created a script that does nothing else other than include the tty gem, I get the same error
alain has quit [Quit: WeeChat 3.2.1]
timkaechele has joined #ruby
timkaechele1 has quit [Ping timeout: 240 seconds]
TCZ has quit [Quit: Leaving]
TCZ has joined #ruby
TCZ has quit [Remote host closed the connection]
ur5us_ has quit [Remote host closed the connection]
ur5us_ has joined #ruby
<weaksauce>
are you using a gemfile?
<weaksauce>
can you gist that
<weaksauce>
and the lock
<adam12>
bobdobbs`: you also need to ensure bundler is being used. either via `bundle exec` or by requiring `bundler/setup`.
<adam12>
and leave off `tty-prompt` from the Gemfile, since `tty` is a meta gem with all the deps.
<bobdobbs`>
ok
<bobdobbs`>
tbh, I'm not entirely clear what bundle does
<bobdobbs`>
*bundler
<adam12>
bobdobbs`: Specifies specific versions of gem dependencies, and sets up the correct loadpaths for them.
<bobdobbs`>
ah, ok. I'm looking at bundler.io now
<adam12>
bobdobbs`: So you can have 3 copies of tty installed (v1, v2, v3) and your Gemfile will say `tty v2`, which bundler will ensure you use (instead of v1 or v3 which may be incompatible)
<bobdobbs`>
ah ok
<bobdobbs`>
So I'm guessing that when I installed tty, Gem installed multiple versions of pastel. And when I run the 'require', ruby sees two different packages and doesn't know which one to use. Is that right?
<adam12>
bobdobbs`: Right. It sounds like either tty-prompt was the issue, or you weren't using bundler (by the 2 methods I mentioned above).