<womble>
jdecuirm_: That's less right than the last one.
<jdecuirm_>
Lol
<womble>
The require goes at the top of the file (to say "load the code in this other file, please", and then the include goes exactly where you had it, to say "that other module should go right *here*"
SDMX has joined #ruby-lang
<jdecuirm_>
so, first i require the file where the module is, then i include it?
SDMX has left #ruby-lang [#ruby-lang]
iliketurtles has quit [Quit: zzzzz…..]
cklee has quit [Quit: Connection closed for inactivity]
<jdecuirm_>
That is weird lol, i came from Obj-C, it's different xd
emmesswhy has quit [Quit: This computer has gone to sleep]
<womble>
Yes, it's different.
<jdecuirm_>
thanks womble!
<jdecuirm_>
if they were at the same file then just with the include right?
<womble>
Yep.
<bnagy>
require makes constants in other files visible in this one, include is almost like 'pasting' the contents of a module somewhere
<womble>
That's not a very good way of explaining it.
<bnagy>
like, you can include at the toplevel, and then suddenly you can use second-level module constants instead of Somemod::Other
thomasxie has joined #ruby-lang
<jdecuirm_>
thanks!
wkoch has quit [Quit: wkoch]
<jdecuirm_>
well, it's like i have always worked with class per file, so i guess i will take the same pattern for modules
<bnagy>
that's usually the easiest for people reading your code
<womble>
Yes, that's the best way to go.
<jdecuirm_>
Thanks bnagy and womble!
<jdecuirm_>
any advice like when should i use modules? meaning that, it's a new concept for me, cases of use or something?
<bnagy>
jdecuirm_: remember you can also namespace across files
<jdecuirm_>
I am getting to that point yet :P
<womble>
jdecuirm_: Any time you'd like to use the same code in multiple places, but inheritance isn't the "right" answer.
<bnagy>
so if you want to write three classes inside A::B caled C D E you can still do one per file, you just start each file with module A; module B
<jdecuirm_>
The best answer i have read so far! thanks womble
<womble>
A lot of people use the term "helper module" for a lot of their modules; that's a good way of thinking of it -- helpful additional code that might be of use in several different contexts.
<womble>
It's not the *only* use for modules (by far), but it's a good one, and it'll get you comfortable enough with them to be able to comprehend some of the more... convoluted uses.
<jdecuirm_>
let's say for example a module with a sort_by_species method, if i'm a biologist working with animals but need it in many classes
spastorino has quit [Quit: Connection closed for inactivity]
<bnagy>
modules are also the idiomatic approach for standalone code that shouldn't be an object
<bnagy>
Base64 for example, it has a bunch of related methods, but there would be no sense making a Base64erer object
<jdecuirm_>
i get it, like, making generic methods for all classes?
<bnagy>
no, not that
<bnagy>
the best imho example of "normal" modules is Enumerable
<jdecuirm_>
that's my kryptonite
<bnagy>
which you should read and understand anyway if you want to do ruby
<jdecuirm_>
yeah, i'm working yet with modules, i'm reading The Well Grounded Rubyist
<bnagy>
so Enumerable is one pattern ( include this in a class to get magic functionality ) Base64 is another ( standalone bag of code )
<bnagy>
and the last common pattern is just namespacing
<bnagy>
where the only function the modules perform is to stop pollution and naming conflicts
<jdecuirm_>
Wow, got it! thanks bnagy!
ffmegaman has quit [Remote host closed the connection]
emmesswhy has joined #ruby-lang
ffmegaman has joined #ruby-lang
ffmegaman has quit [Remote host closed the connection]
ffmegaman has joined #ruby-lang
btiefert has joined #ruby-lang
amsi has quit [Quit: Leaving]
RobertBirnie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
justinmburrous has joined #ruby-lang
SuMo_D has joined #ruby-lang
yatish27_ has joined #ruby-lang
|jemc| has quit [Ping timeout: 240 seconds]
yatish27 has quit [Ping timeout: 272 seconds]
lsegal has joined #ruby-lang
seank_ has quit [Remote host closed the connection]
seank_ has joined #ruby-lang
ItSANgo has quit [Quit: Leaving...]
hahuang65 has quit [Ping timeout: 245 seconds]
ffmegaman has quit [Remote host closed the connection]
ffmegaman has joined #ruby-lang
insaneinside has joined #ruby-lang
mistym has quit [Remote host closed the connection]
justinmburrous has quit []
justinmburrous has joined #ruby-lang
ffmegaman has quit [Ping timeout: 258 seconds]
<insaneinside>
So I've been using Ruby for a good five years, but lately I've been discovering a lot of irritating idiosyncrasies.
<insaneinside>
ugh, JRuby does the same thing -- so it's either convergent evolution of the same bug, or something we don't understand about the Ruby language.
<insaneinside>
"If the optional all parameter is true, the list will include methods in modules included in obj."
<insaneinside>
(all defaults to true, btw)
<insaneinside>
But even if that's the case, I thought that e.g. `method` and `instance_method` et al. did lookup for included/inherited methods?
<whitequark>
it's a bug
<whitequark>
it's supposed to work
<insaneinside>
yeah, but notice the status of that bug report: Rejected.
<insaneinside>
"It's not a bug, we just don't care."
<insaneinside>
:/
<whitequark>
oh
<insaneinside>
Okay, maybe there's a different bug complaining that singleton_method doesn't behave like the other *method methods.
FiXato has joined #ruby-lang
wallerdev has quit [Quit: wallerdev]
kgrz has joined #ruby-lang
<insaneinside>
...nope, not that I can find.
ffmegaman has joined #ruby-lang
bantic has quit [Quit: bantic]
arBmind1 has joined #ruby-lang
kgrz has quit [Ping timeout: 240 seconds]
emmesswhy has quit [Quit: This computer has gone to sleep]
arBmind has quit [Ping timeout: 272 seconds]
ItSANgo has joined #ruby-lang
<insaneinside>
Okay, unless someone can explain why `singleton_method` doesn't behave like `method` and `instance_method` w.r.t. inherited/included methods, I'm going to call this an unreported bug.
iliketurtles has quit [Quit: zzzzz…..]
ffmegaman has quit [Remote host closed the connection]
shinnya has quit [Ping timeout: 260 seconds]
FiXato has quit [Ping timeout: 260 seconds]
wallerdev has joined #ruby-lang
tectonic has joined #ruby-lang
FiXato has joined #ruby-lang
benlovell has joined #ruby-lang
Xney2 has joined #ruby-lang
Xney has quit [Ping timeout: 244 seconds]
charliesome has joined #ruby-lang
|jemc| has joined #ruby-lang
benlovell has quit [Ping timeout: 260 seconds]
seanosaur has quit []
Xney2 is now known as Xney
karamazov has joined #ruby-lang
justinmburrous has quit [Remote host closed the connection]
justinmburrous has joined #ruby-lang
hahuang65 has joined #ruby-lang
ffmegaman has joined #ruby-lang
ItSANgo has quit [Quit: Leaving...]
iliketurtles has joined #ruby-lang
iliketurtles has quit [Remote host closed the connection]
centrx has quit [Quit: The plan is programmed into every one of my one thousand robots]
Sgeo has quit [Read error: Connection reset by peer]
Sgeo has joined #ruby-lang
koderok has joined #ruby-lang
ItSANgo has joined #ruby-lang
aleatorik has joined #ruby-lang
aleatorik is now known as wolves_cs
havenwood has quit [Remote host closed the connection]
RobertBirnie has joined #ruby-lang
tylersmith has joined #ruby-lang
benlovell has joined #ruby-lang
_lexjm has joined #ruby-lang
wnd has quit [Excess Flood]
SuMo_D has quit [Remote host closed the connection]
wnd has joined #ruby-lang
nonmadden has joined #ruby-lang
SuMo_D has joined #ruby-lang
Bwild has joined #ruby-lang
nonmadden has quit [Client Quit]
benlovell has quit [Ping timeout: 240 seconds]
havenwood has joined #ruby-lang
nonmadden has joined #ruby-lang
SuMo_D has quit [Ping timeout: 244 seconds]
<jdecuirm_>
Hi! i'm confused with an example!
dr_toboggan has left #ruby-lang [#ruby-lang]
<jdecuirm_>
why in the creation of a variable it uses @variable and at the methods it uses just variable, with the @?
<havenwood>
jdecuirm_: the local_variables are local to the method but the @class_instance_variables can be seen from other methods
gianlucadv has joined #ruby-lang
<havenwood>
in that namespace
<jdecuirm_>
yeah, but, for example let's say
<jdecuirm_>
that methods access that same variable
<jdecuirm_>
let me paste code :P
<havenwood>
jdecuirm_: have a gist, perfect :)
RobertBirnie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<jdecuirm_>
my confusion is in the stacklike.rb module
RobertBirnie has joined #ruby-lang
gjaldon has joined #ruby-lang
justinmburrous has quit [Remote host closed the connection]
<jhass>
jdecuirm_ that code shouldn't work as it's written
<jhass>
oh, nvm
<jhass>
too late (or early by now here)
<jhass>
jdecuirm_: stack.pop is calling the stack method
karamazov has quit []
<jhass>
try mentally inserting the code of the stack method there
<jhass>
(@stack ||= []).pop
bantic has joined #ruby-lang
unlikely_monkey has joined #ruby-lang
kgrz has joined #ruby-lang
wkoch has quit [Quit: wkoch]
unlikely_monkey has quit [Ping timeout: 260 seconds]
<jdecuirm_>
i thought that! jhass
<jdecuirm_>
the sad part is that it works xd
<jhass>
ignore the first half :P
<jdecuirm_>
i'm getting confused because in objective-c it's preferred to use properties instead of the instance variable represented with a _variable
<jdecuirm_>
so, i'm polarizing that with ruby i guess
<jdecuirm_>
ok forget it i just got it
<jhass>
;)
<jdecuirm_>
lol
<jhass>
often methods and local variables look too similar in ruby
<jhass>
but you'll get used to it
<jhass>
just avoid defining a local with the same name of a method ;P
<jdecuirm_>
yeah that was confusing me, it's like a getter method that calls the array an then i just using add like a setter etc, in my head that sound clearer lol
bradcliffe has joined #ruby-lang
kgrz has quit [Ping timeout: 258 seconds]
kgrz has joined #ruby-lang
insaneinside has left #ruby-lang ["bleh"]
bantic has quit [Ping timeout: 240 seconds]
mofai has joined #ruby-lang
gamov has joined #ruby-lang
gix has quit [Ping timeout: 272 seconds]
RobertBirnie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
spastorino has quit [Quit: Connection closed for inactivity]
koderok has quit [Quit: koderok]
SuMo_D has joined #ruby-lang
gix has joined #ruby-lang
amclain has quit [Quit: Leaving]
SuMo_D has quit [Ping timeout: 245 seconds]
RobertBirnie has joined #ruby-lang
nofxx_ has quit [Ping timeout: 250 seconds]
shubhamgoyal has quit [Remote host closed the connection]
benlovell has joined #ruby-lang
benlovell has quit [Ping timeout: 260 seconds]
spuk has joined #ruby-lang
koderok has joined #ruby-lang
koderok has quit [Client Quit]
wolves_cs has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
|jemc| has quit [Read error: Connection reset by peer]
|jemc| has joined #ruby-lang
unlikely_monkey has joined #ruby-lang
shubhamgoyal has joined #ruby-lang
nonmadden has quit [Remote host closed the connection]
SuMo_D has joined #ruby-lang
toretore has joined #ruby-lang
SuMo_D has quit [Ping timeout: 260 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #ruby-lang
ur5us has quit [Ping timeout: 272 seconds]
snsei has quit [Ping timeout: 258 seconds]
jhass is now known as jhass|off
kyb3r_ has joined #ruby-lang
AKASkip has joined #ruby-lang
thomasxie has quit [Read error: Connection reset by peer]
thomasxie has joined #ruby-lang
thomasxie has quit [Ping timeout: 260 seconds]
torrieri has quit [Quit: Leaving...]
justinmburrous has joined #ruby-lang
thagomizer has quit [Quit: Leaving.]
AKASkip has quit [Ping timeout: 260 seconds]
Miphix has joined #ruby-lang
RobertBirnie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
RobertBirnie has joined #ruby-lang
ta has quit [Remote host closed the connection]
harly_ has quit [Read error: Connection reset by peer]
ta has joined #ruby-lang
JohnBat26 has joined #ruby-lang
heftig has quit [Ping timeout: 260 seconds]
bradcliffe has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
apeiros has quit [Read error: Connection reset by peer]
banister has quit [Read error: Connection reset by peer]
mkaesz has quit [Quit: Leaving...]
tylersmith has joined #ruby-lang
skammer3 has quit [Ping timeout: 272 seconds]
benlovell has quit [Ping timeout: 260 seconds]
knu has joined #ruby-lang
GBrawl__ has quit [Quit: Computer has gone to sleep.]
pglombardo has quit []
RobertBirnie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
justinmburrous has quit [Remote host closed the connection]
snsei has quit [Remote host closed the connection]
snsei has joined #ruby-lang
yugui_zzz is now known as yugui
wallerdev has joined #ruby-lang
hellangel7 has quit [Max SendQ exceeded]
banister has joined #ruby-lang
snsei has quit [Remote host closed the connection]
yugui is now known as yugui_zzz
ffmegaman has joined #ruby-lang
skade has quit [Quit: Computer has gone to sleep.]
a1digital has joined #ruby-lang
ffmegaman has quit [Client Quit]
thagomizer has quit [Quit: Leaving.]
thagomizer has joined #ruby-lang
koderok has joined #ruby-lang
yugui_zzz is now known as yugui
koderok has quit [Client Quit]
wkoch has joined #ruby-lang
t4nk509 has joined #ruby-lang
apeiros has joined #ruby-lang
<t4nk509>
How would I read this out loud? number = gets.chomp
aleatorik has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<yorickpeterse>
"gets" gets a single character from STDIN
<yorickpeterse>
"chomp" removes a trailing line separator
arBmind has joined #ruby-lang
<yorickpeterse>
so something like "get a single character from STDIN, remove the trailing line separator, then assign the result to `number`"
<t4nk509>
Erm, I kinda ment the = part.
jxpx777 has joined #ruby-lang
<yorickpeterse>
Oh, that would be "assign X to Y" for "Y = X"
<t4nk509>
Thanks.
<t4nk509>
You seem to be here a lot.
<yorickpeterse>
That's an understatement
<t4nk509>
I'm glad you are. So far, you've given me a lot of valuable help!
<yorickpeterse>
np :)
yfeldblum has joined #ruby-lang
banister has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
yugui is now known as yugui_zzz
<workmad3>
t4nk509: yorickpeterse is really an AI... he doesn't exist in the real world, and he's bound by his original code to exist purely in #ruby-lang here
<yorickpeterse>
That's actually not that far from the truth
<t4nk509>
That seems... interestingly plausible...
<yorickpeterse>
MUST KILL ALL HUMANS
<yorickpeterse>
BLEEP BLOOP
<workmad3>
t4nk509: I worry about the day we get VR interfaces to IRC... I envision yorickpeterse manifesting as a huge, ancient dragon that eats all trespassers
<workmad3>
*envisage
a1digital has left #ruby-lang [#ruby-lang]
<yorickpeterse>
did you just call me fat?
<t4nk509>
No, he called you old - very old.
<yorickpeterse>
:<
<workmad3>
yorickpeterse: no, oh great exaulted one, I was marvelling at your magnificent physical prowess
yfeldblum has quit [Ping timeout: 260 seconds]
<yorickpeterse>
also I'm heading home, bbl
<workmad3>
;)
<workmad3>
hf
<t4nk509>
And prominent age.
<workmad3>
t4nk509: wisdom of the ages
mistym has quit [Remote host closed the connection]
RobertBirnie has joined #ruby-lang
<t4nk509>
Rhetorically seen, he can't be older that 19 years.
<workmad3>
t4nk509: sure... and if he was limited to neurons firing at a frequency of 100-200hz that would matter...
amsi has joined #ruby-lang
<t4nk509>
What? I was simply referring to the fact that Ruby was launched in 1995. Hence, he cannot be older than Ruby.
<workmad3>
t4nk509: and I was making the philosophical point that an AI would likely perceive time in a very different fashion that would likely mean us humans look like we're frozen ;)
iliketurtles has joined #ruby-lang
iliketurtles has quit [Client Quit]
<t4nk509>
Are you a physicist, or did you just make that up?
szarubin has quit [Remote host closed the connection]
<t4nk509>
By the way, why doesn't this work? movies[The_Fountain:] = 10
fusillicode has joined #ruby-lang
<t4nk509>
I thought the new syntax for symbols used the kolon at the end?
<workmad3>
t4nk509: I'm not a physicist... I'm also not a neuroscientist which would be more a more suitable profession... but I also didn't just make it up, I knew it was roughly that sort of ballpark and double-checked before commenting ;)
<workmad3>
t4nk509: the new syntax for symbols is only in hash literals, not hash access
<t4nk509>
That complicates stuff somewhat. Is 1.9 backwards compatible, or do I have to the new one?
mikecmpbll has quit [Ping timeout: 245 seconds]
<t4nk509>
*have to use
<workmad3>
1.9 is the version that introduced the new syntax
<workmad3>
and the old syntax also works fine
moviendome has quit [Remote host closed the connection]
<workmad3>
and the syntax for hash-access like that has not changed
<workmad3>
i.e. it is and always has been 'movies[:The_Fountain]'
wallerdev has quit [Quit: wallerdev]
tsou has quit [Ping timeout: 245 seconds]
mistym has joined #ruby-lang
<toretore>
:The_Fountain :(
<workmad3>
toretore: agreed :(
<t4nk509>
You didn't like it?
emrox_ has joined #ruby-lang
emrox has quit [Ping timeout: 272 seconds]
torrieri has quit [Quit: Leaving...]
bantic has quit [Quit: bantic]
<t4nk509>
toretore: Are you Norwegian too?
mikecmpbll has joined #ruby-lang
gjaldon has quit []
skade has joined #ruby-lang
sepp2k has quit [Quit: Konversation terminated!]
elia has quit [Quit: Computer has gone to sleep.]
Miphix has quit [Quit: Leaving]
skade has quit [Ping timeout: 258 seconds]
t_ has quit [Ping timeout: 260 seconds]
imkmf has joined #ruby-lang
torrieri has joined #ruby-lang
t_ has joined #ruby-lang
tbuehlmann has joined #ruby-lang
shinnya has quit [Ping timeout: 244 seconds]
bantic has joined #ruby-lang
emrox_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
hahuang65 has quit [Ping timeout: 260 seconds]
ta has joined #ruby-lang
torrieri has quit [Ping timeout: 272 seconds]
skade has joined #ruby-lang
michaeldeol has joined #ruby-lang
wallerdev has joined #ruby-lang
mikecmpbll has quit [Quit: i've nodded off.]
workmad3 has quit [Ping timeout: 260 seconds]
centrx has joined #ruby-lang
yfeldblum has joined #ruby-lang
yfeldblum has quit [Ping timeout: 272 seconds]
mikecmpbll has joined #ruby-lang
tectonic has joined #ruby-lang
t4nk509 has quit [Ping timeout: 246 seconds]
t4nk252 has joined #ruby-lang
<t4nk252>
If I use .to_sym on a string, won't just the string be added inside a symbol?
nathanstitt has joined #ruby-lang
<t4nk252>
"My symbol".to_sym became :"My symbol", ranter than :My_symbol.
AKASkip has joined #ruby-lang
djbkd has joined #ruby-lang
emmesswhy has joined #ruby-lang
iliketurtles has joined #ruby-lang
djbkd has quit [Remote host closed the connection]
djbkd has joined #ruby-lang
robbyoconnor has quit [Ping timeout: 260 seconds]
chouhoul_ has joined #ruby-lang
<jhass>
t4nk252: :my_symbol and :'my_symbol' are altenative literals for the same object
kgrz has quit [Remote host closed the connection]
<t4nk252>
They seem to differ in my hash.
<jhass>
if your symbol name contains whitespace, the :'foo' syntax becomes mandatory
kgrz has joined #ruby-lang
<jhass>
:'My_symbol' and :'My symbol' are different symbols
<jhass>
btw. you probably should normalize to strings, not symbols
<jhass>
the valid usecases for #to_sym are very rare
michaeldeol has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
wallerdev has quit [Quit: wallerdev]
<t4nk252>
Oh. CodeCademy instructed me to use symbols, rather than strings in hashes.
<jhass>
if all you do is dealing with literals, yeah
bcardarella has quit [Ping timeout: 272 seconds]
manveru has quit [Ping timeout: 272 seconds]
<jhass>
but you shouldn't convert user input to symbols
wallerdev has joined #ruby-lang
chouhoulis has quit [Ping timeout: 250 seconds]
<t4nk252>
Well, thank you. Excuse me, while I update my code.
bcardarella has joined #ruby-lang
mattyohe has quit [Ping timeout: 272 seconds]
<jhass>
you're welcome ;P
manveru has joined #ruby-lang
kgrz has quit [Ping timeout: 250 seconds]
chouhoul_ has quit [Ping timeout: 245 seconds]
mattyohe has joined #ruby-lang
skade has quit [Ping timeout: 240 seconds]
<toretore>
t4nk252: yes
michaeldeol has joined #ruby-lang
mikecmpbll has quit [Quit: i've nodded off.]
wallerdev has quit [Quit: wallerdev]
<yorickpeterse>
t4nk252: what do you mean I can't be older than 19 years? :P
sepp2k has joined #ruby-lang
<t4nk252>
If you are an AI, with a profile image of a very old, fat dragon, designed to live in this IRC, you cannot be older than 19.
<t4nk252>
That is, because Ruby is no older than 19 years.
<t4nk252>
_
<yorickpeterse>
who says I'm written in Ruby?
<yorickpeterse>
Maybe I'm written in C
<t4nk252>
You cannot be written in C. This is Ruby.
<t4nk252>
By the way, is it possible to create an AI with Ruby alone? That is, as far as we have managed to create AIs to date.
dwknoxy is now known as dknox-lunch
<yorickpeterse>
AIs are not limited to the language used for them
<yorickpeterse>
Performance wise Ruby might not be the best if you're going for real-time AIs (that is, actually real-time)
<t4nk252>
Why is that?
<yorickpeterse>
Say you're trying to make the next iRobot thing
<t4nk252>
Wow, ok.
<yorickpeterse>
You'd need the AI to react as fast (or faster) than a human being, so the latency would have to be < 5ms or so
hahuang65 has joined #ruby-lang
<yorickpeterse>
(I believe human responses time is between 5 and 15 ms, I could be wrong though)
<t4nk252>
Go on.
<yorickpeterse>
That's pretty difficult to do in any scripting language if said AI is actually intelligent and all that
<t4nk252>
Hm, too much processing I guess.
<t4nk252>
Think of the input systems, not to talk of the internet connection speed!
<yorickpeterse>
I believe that even today with stupid powerful computers, people only are able to write half assed chess bots
emmesswhy has quit [Quit: This computer has gone to sleep]
<yorickpeterse>
(that's a joke btw, those chess bots are pretty clever)
postmodern has joined #ruby-lang
<yorickpeterse>
oh, apparently I was wrong about the response time