<treydt>
So I was using a ruby guide this morning, and I can't find it again. It went from information about strings, to arrays, then to hash maps.
<treydt>
Any idea which one it was?
havenn has joined #ruby
fantazo has joined #ruby
ringotwo_ has quit [Remote host closed the connection]
azm has quit [Ping timeout: 272 seconds]
khakimov has joined #ruby
khakimov has quit [Client Quit]
havenn has quit [Ping timeout: 245 seconds]
seoaqua has joined #ruby
ken_barber has joined #ruby
ken_barber has quit [Remote host closed the connection]
Poapfel has joined #ruby
ken_barber has joined #ruby
flexd has joined #ruby
justsee is now known as justsee|away
n_blownapart has joined #ruby
mmokrysz has joined #ruby
mmokrysz has left #ruby [#ruby]
SCommette has quit [Ping timeout: 252 seconds]
mahmoudimus has quit [Quit: Computer has gone to sleep.]
<n_blownapart>
http://pastie.org/4525122 -- Hi. I'm wondering why this prog. explaining protected methods uses n as the method name, since the constructor also uses n which I assume stands for number. is it intentionally confusing or am I reading it wrongly? thanks.
jarred has quit [Quit: jarred]
havenn has joined #ruby
havenn has quit [Remote host closed the connection]
ken_barber has quit [Ping timeout: 240 seconds]
beneggett has joined #ruby
tommyvyo has quit [Quit: Computer has gone to sleep.]
cakehero has joined #ruby
gavit has quit [Read error: Connection timed out]
tommyvyo has joined #ruby
igotnolegs has joined #ruby
justinmcp has quit [Remote host closed the connection]
gavit has joined #ruby
wpaulson has joined #ruby
ryanf has joined #ruby
pricees has joined #ruby
axl_ has joined #ruby
tommyvyo has quit [Changing host]
tommyvyo has joined #ruby
slyv has quit [Quit: Cya!]
<n_blownapart>
anyone willing to explain this prog esp. line 11 and also why book author chose to name the method n when the constructor has n as its parameter. thanks: http://pastie.org/4525122
evenix has quit [Remote host closed the connection]
<pabloh>
is there a way to edit openoffice sreadsheets from ruby?
t92726 has quit [Remote host closed the connection]
<epitron>
n_blownapart: that's a weird example. normally, if you want to be able to compare objects, you implement the <=> method, and include comparable
Guedes has quit [Remote host closed the connection]
t19775 has joined #ruby
SCommette has joined #ruby
baroquebobcat has quit [Client Quit]
<n_blownapart>
epitron: thanks for answering. the point is the protected method. but this prog. confuses me.
<n_blownapart>
epitron: I'm assuming the n in the constructor stands for number, right?
<epitron>
i dunno why he'd make that protected. that's pretty predantic :)
<epitron>
it's a weird program that has no purpose
baroquebobcat has joined #ruby
<n_blownapart>
epitron: it shows how only two objects of the same class can use the protected method among themselves. but could I ask you some things in the context of the example?
<epitron>
okay
<epitron>
sure, ask away
<n_blownapart>
epitron: first, why doesn't he use num in the constructor ie. def initialize(num)
<n_blownapart>
epitron: because he uses n as the method name.
<ryanf>
n_blownapart: if n and @n are good enough to be the name of the accessor and the instance variable
<ryanf>
there's no reason not to name the corresponding constructor param the same thing
<ryanf>
in this case it's kind of hard to see that, since n is a horrible name for an attribute
khakimov has joined #ruby
<ryanf>
but in real life, it usually makes sense to use the same name for all three of those things
<epitron>
yeah.. it would be confusing if it was like: initialize(a_number); @the_number = a_number; end
<epitron>
well, that's not so bad
<drupin>
bundle exec rake db:migrate.... gives me No such file or directory - pg_dump -i -s -x -O -f /home/...../git-......./db/structure.sql database-name
<n_blownapart>
sorry ryanf I don't understand it in those terms. wouldn't it be def n; @num; end ?
<epitron>
but regularity and predictability are very useful coding standards
<epitron>
the less thinking you have to do, the better :)
<n_blownapart>
because n is just a method that holds a numeric value, right? epitron ryanf
<epitron>
hmm
<epitron>
well, you wouldn't want to do that
<epitron>
you should name the accessor after the variable
<epitron>
and the standard way of generating that method is: attr_reader :num
<epitron>
:)
<n_blownapart>
epitron: sorry I don't get it at all then.
k_89 has joined #ruby
<epitron>
def num; @num; end
<epitron>
it's that regularity thing again
<epitron>
attr_reader :num generates the method def num; @num; end
apok has joined #ruby
<epitron>
it lets you make getters/setters with less code
<epitron>
attr_reader :var1, :var2, :var3, :var4
<n_blownapart>
epitron: that I understand. but the way you're explaining this ....sorry you're losing me.
<epitron>
haha
<epitron>
i don't know why i'm explaining it
<epitron>
it's very basic stuff
nari has joined #ruby
<epitron>
it's mostly coding style
<epitron>
you can name your methods/variables whatever you want
<epitron>
phanousit: if you want to do a lot of work with ratios (adding them together, etc.) and then finally finding the percent, i made this: http://rdoc.info/github/epitron/epitools/Ratio
tds has quit [Client Quit]
<phanousit>
epitron: thanks
gavit has quit [Read error: Connection timed out]
banisterfiend has quit [Ping timeout: 240 seconds]
<n_blownapart>
epitron: hey could we just go over quickly, starting at line 11: if c.n > n ?
<epitron>
ok
gavit has joined #ruby
<epitron>
what do you want to know?
opus has quit [Quit:]
walbert has quit []
baroquebobcat has quit [Quit: baroquebobcat]
Banistergalaxy has quit [Ping timeout: 245 seconds]
TorpedoSkyline has quit [Quit: ["Textual IRC Client: www.textualapp.com"]]
<n_blownapart>
thanks epitron the number 101 gets sent as the argument so it is essentially if 100.n > n ?
<epitron>
no
baroquebobcat has joined #ruby
<epitron>
c is an instance of C
darren has quit [Remote host closed the connection]
<epitron>
C has an n method
<epitron>
n returns 101
<n_blownapart>
epitron: which is initialized in this case with 101.
crise has joined #ruby
<epitron>
yes
crise has left #ruby [#ruby]
Banistergalaxy has joined #ruby
<n_blownapart>
epitron: thats why I'm confused. n returns 101 , or is the C obj. initialized with 101?
baroquebobcat has quit [Client Quit]
<epitron>
n is a method
justinmcp has quit [Remote host closed the connection]
iamjarvo has joined #ruby
<epitron>
when you say c.n it calls n on the object c
<epitron>
when you say n inside the class, it calls the n method
<epitron>
it could also be written: if c.n > self.n
<epitron>
the only time n isn't a method is in initialize
jellosea_ has joined #ruby
<jellosea_>
hey, if i have an array and i want to iterate through it, and in the iteration block i want to have a list of the array im iterating over except for the current item, how would i do that?
<n_blownapart>
epitron: that sheds light, because n is fulfilling the name of the method and the parameter in the constructor. I've never seen this (I'm a noob to programming.)
verbad has joined #ruby
<epitron>
n_blownapart: do you know what scopes are?
t19775 has quit [Remote host closed the connection]
t43360 has joined #ruby
<epitron>
jellosea_: array.each{|e| array-[e] }
<n_blownapart>
yeah epitron self changes as the program progresses.
baroquebobcat has joined #ruby
<lledet>
hi, i want to provide a download link that hides the original link (not not my server) is there a way to send the file without revealing the actual link?
<epitron>
n_blownapart: no, scope means "what you can see from this line of code"
<jellosea_>
epitron: thanks!
<epitron>
n_blownapart: say, i have a method: def scopey; x = 5; end...
<epitron>
x is only visible from within scopey
<epitron>
that's scope's "scope"
<epitron>
*scopey
<n_blownapart>
epitron: right, so n is moving around and taking on various capacities, but its really just either 100 or 101.
<epitron>
agh
<epitron>
no, it's not moving
<epitron>
it's like a chain of lookups
<epitron>
if you say "n > 1".. it has to find what n is
<epitron>
first it checks local variables
<n_blownapart>
epitron: right. I see that
<epitron>
local variables are variables defined inside the current method
<n_blownapart>
right epitron
<epitron>
then it assumes you were calling a method, so it checks methods in the class you're in
<epitron>
then if it still doesn't find it, it looks for methods in the superclass
<epitron>
and keeps doing that until it gets to the mother of all classes, Object
adamkittelson has quit [Remote host closed the connection]
<n_blownapart>
ok. yeah epitron I was working with super , etc. and method_missing. but this is the thing: if you were to rewrite this exact prog. with different var. names and parameters, would you have better choices?
mrdodo has joined #ruby
<epitron>
would i choose different names?
<n_blownapart>
its the nomenclature that is confusing me, I think. yeah choose different ones epitron?
<epitron>
hahah
<epitron>
i still don't get what's confusing you
<epitron>
the names don't matter here beacuse this class has no purpose
<epitron>
it's just a demo of how to use proteted
<epitron>
n is a fine name for a class with no meaning
<epitron>
s/for/in/
<n_blownapart>
the fact that the method name and the parameter name in the constructor are shared. that's funny
<n_blownapart>
epitron: ^
<epitron>
imagine it meant something
<epitron>
say the variable was "address"
<epitron>
write the class both ways
<epitron>
with the same name, and with different names
<Banistergalaxy>
Epitron is a friendly kind of bloke, youre lucky to have his attention
<epitron>
and notice that the different names start to get confusing
<n_blownapart>
epitron: well I thought num was more descriptive.
<Banistergalaxy>
A man you can trust.
<epitron>
num is more descriptive
<epitron>
but you should make everything num then!
<n_blownapart>
def n; @num; end right, epitron?
verbad has quit []
<epitron>
def num; @num
<epitron>
why would you call the same thing two different things??
<epitron>
def name; @person_name; end
<epitron>
def intitialize(name_of_person; @name = name_of_person; end
<n_blownapart>
epitron: but one is the method name, the other is the instance var. holding numeric values...
<epitron>
so?
<epitron>
the method returns the variable
<epitron>
it means the same thing as the variable
<epitron>
@n and n return the exact same thing
<epitron>
it's THE SAME THING
<epitron>
call it the SAME THING :)
andrewhl has quit [Remote host closed the connection]
MarioEIU has joined #ruby
gavit has quit [Read error: Connection timed out]
seoaqua has quit [Ping timeout: 265 seconds]
gavit has joined #ruby
<n_blownapart>
epitron: ok. I just thought this made more sense: def initialize(num); @num = num; end; def n; @num; end
<epitron>
so close
<epitron>
def num; @num; end
randomautomator has joined #ruby
<epitron>
now it makes the most sense
<epitron>
(aside from the fact that the entire class is just a container for a number, which is pointless)
<epitron>
:)
<n_blownapart>
epitron: so don't use num and n, to discriminate between the param and the method name. Ok, I'm going to try to grok that.
<n_blownapart>
epitron: many thanks.
<epitron>
here's all you have to grok: they are THE SAME THING :)
justinmcp has joined #ruby
<epitron>
if it was a person, you'd call them both person
<epitron>
it would be weird to call one p and the other person
hemanth has joined #ruby
<epitron>
anyhow, you will grok it as you code more
<n_blownapart>
epitron: but method name describes a function. @num holds a value. that's what I thought was protocol, anyway.
insecurlex has joined #ruby
<n_blownapart>
epitron: thanks I really appreciate the patience of people in this irc
pricees has quit [Ping timeout: 272 seconds]
<epitron>
>_<
uris has quit [Quit: leaving]
cakehero has quit [Quit: Leaving...]
<n_blownapart>
epitron: sometimes I think the examples are poor when single letters are used...there's no context to grasp ideas and it seems unnecessarily abstract.
mikepack has quit [Remote host closed the connection]
<epitron>
YOU ARE CORRECT SIR
Michael has joined #ruby
Michael is now known as meskyanichi
diegoviola has joined #ruby
emmanuelux has quit [Ping timeout: 268 seconds]
t43360 has quit [Remote host closed the connection]
mmokrysz has joined #ruby
t47835 has joined #ruby
mmokrysz has left #ruby [#ruby]
<n_blownapart>
epitron: yeah, when you said that the prog was just a container for a number it was helpful...I thought more was going on.
<phanousit>
hey can someone help me with me code? i need it to stop looping all the way to the top.
<epitron>
phanousit: if you want to make the game more fun, you can add extra parameters to weapon
<epitron>
weapon 2, "soft pillow"
<phanousit>
epitron: thanks, thats my goal
<epitron>
weapon 7, "extension cord"
pu22l3r has quit [Ping timeout: 246 seconds]
<epitron>
weapon 172375, "the gaze of god"
justsee|away is now known as justsee
<phanousit>
epitron: how long have you been doing ruby?
<epitron>
since 2005
azm has joined #ruby
<phanousit>
nice
pu22l3r_ has quit [Ping timeout: 260 seconds]
`brendan has quit [Ping timeout: 240 seconds]
<phanousit>
I'm trying to make this game so that i can get an internship
ringotwo has joined #ruby
baroquebobcat has quit [Quit: baroquebobcat]
<epitron>
ah
t47835 has quit [Remote host closed the connection]
<epitron>
well, good luck on that
t9637 has joined #ruby
trollface is now known as Paradox
<epitron>
here's another possibility: instead of only putting an attack command on the main character, you can put it on all enemies
<epitron>
so enemies can attack each other
<epitron>
every attack is followed by a counter-attack
baroquebobcat has joined #ruby
butblack has left #ruby [#ruby]
dhruvasagar has quit [Ping timeout: 246 seconds]
<epitron>
haha.. actually.. you could have every fight carried out completely with one command
khakimov has quit [Quit: Computer has gone to sleep.]
<epitron>
def fight(other); self.attack(other); other.fight(self); end
<epitron>
that would loop forever, until one of them died
<phanousit>
can you explain what self does?
<epitron>
ugh
<epitron>
read about it
<phanousit>
ok
Banistergalaxy has quit [Ping timeout: 268 seconds]
<phanousit>
say, i want to attach attributes to the hero character
<phanousit>
should i put them a hash?
<phanousit>
like :hp, :attack etc....
dhruvasagar has joined #ruby
ananthakumaran has quit [Quit: Leaving.]
Rajesh has joined #ruby
Rajesh is now known as Guest1496
aldodelgado has joined #ruby
<pabloh>
does anybody know how to modify openoffice sreadsheets from ruby?
MarioEIU has quit [Quit: Leaving]
yasushi has joined #ruby
Guest1496 has quit [Max SendQ exceeded]
<epitron>
phanousit: n_blownapart already completely depleted me of patience for noob questions.. you're going to have to answer this on your own. i recommend reading that article, which has a good system.
<phanousit>
yeah i see
<phanousit>
thanks a lot
yakko has joined #ruby
Guest1496 has joined #ruby
burgestrand has quit [Quit: Leaving.]
<n_blownapart>
epitron please forego it next time.
qko has quit [Ping timeout: 240 seconds]
phanousit is now known as siameseguy
pv_ has joined #ruby
kenneth has quit [Quit: kenneth]
seoaqua has joined #ruby
gavit has quit [Read error: Connection timed out]
gavit has joined #ruby
qko has joined #ruby
nari has quit [Read error: Connection reset by peer]
mxbtty has joined #ruby
randomautomator has quit [Remote host closed the connection]
krz has quit [Quit: krz]
greasegum has quit [Ping timeout: 246 seconds]
Araxia has joined #ruby
mohits has joined #ruby
t9637 has quit [Remote host closed the connection]
t75826 has joined #ruby
kuzushi has joined #ruby
Z_Mass has joined #ruby
pu22l3r has joined #ruby
<treydt>
Kay.
<treydt>
I just saw class Something < SomethingElse::SomethingElse
<treydt>
...Class X < Y::Z
<treydt>
What's the <?
<ryanf>
inheritance
<bnagy>
inheritance
<ryanf>
bnagy: o/
<bnagy>
ryanf: fu, get a name with a different length :D
<treydt>
I'm going to say something terrible here, but bear with me - inheriting a class within a class?
graspee has quit [Quit: leaving]
<ryanf>
Y could also be a module
<bnagy>
no Y::Z is just precise
<ryanf>
yes, for some definition of "within"
pu22l3r has quit [Remote host closed the connection]
<bnagy>
Y plays no part in the proceedings, it's just part of the namespace that gets you to Z
pu22l3r has joined #ruby
<ryanf>
yes
<ryanf>
Z does happen to be inside Y though
kenneth has joined #ruby
<epitron>
treydt: think of it like directories... you have have a directory that contains other directories
kenneth has quit [Client Quit]
<epitron>
classes can contain other classes
<treydt>
What could the definition of Y look like?
<epitron>
class Y
<epitron>
end
<epitron>
end
<epitron>
class Z
<treydt>
Got it. Mucho gracias.
<epitron>
no problemo
Banistergalaxy has joined #ruby
pv_ has quit [Remote host closed the connection]
jenrzzz has quit [Ping timeout: 240 seconds]
alexy_ has left #ruby ["Leaving"]
yaymukund has quit [Ping timeout: 272 seconds]
gavit has quit [Read error: Connection timed out]
gavit has joined #ruby
TheLZA has joined #ruby
TheLZA has quit [Max SendQ exceeded]
SCommette has quit [Quit: SCommette]
TheLZA has joined #ruby
TheLZA has quit [Max SendQ exceeded]
TheLZA has joined #ruby
TheLZA has quit [Max SendQ exceeded]
TheLZA has joined #ruby
TheLZA has quit [Max SendQ exceeded]
n_blownapart has quit [Remote host closed the connection]
yakko has quit [Remote host closed the connection]