Emmanuel_Chanel has quit [Ping timeout: 252 seconds]
d3vic3 has joined #ruby
tonni has joined #ruby
Russell^^ has joined #ruby
_justin has quit [Ping timeout: 264 seconds]
br4ndon has quit [Quit: Lorem ipsum dolor sit amet]
hoelzro|away is now known as hoelzro
arturas has joined #ruby
br4ndon has joined #ruby
arturas has quit [Client Quit]
arturaz has joined #ruby
Araxia has joined #ruby
iamjarvo has quit [Read error: Connection reset by peer]
beneggett has quit [Quit: Computer has gone to sleep.]
<shevy>
hmmm
Araxia has quit [Client Quit]
<shevy>
when I want 10 different classes to all have a @foo variable
<shevy>
and this @foo variable defaults to false
<shevy>
can I use a module for this? or must I subclass from a base class
<workmad3>
either
<Hanmac>
shevy; module ABC; attr_accessor :foo; end class XYZ; include ABC; end
<shevy>
hmm no
<shevy>
only a @foo variable
<shevy>
is there an include hook? when module foo is included, do this and that ?
<workmad3>
shevy: there is, but it's at the class level
mockra has joined #ruby
<workmad3>
shevy: so it gets run when the module is included in a class
<Hanmac>
module ABC; def initialize; @foo = false; end;end class XYZ; include ABC; end
Emmanuel_Chanel has joined #ruby
<workmad3>
Hanmac: bad... you forgot to call 'super if defined?(super)' in your initialize :P
<shevy>
whoa
<hoelzro>
Hanmac: what if the consuming class defines initialize, though?
<shevy>
how does that work?
<shevy>
I mean that a module has a initialize method
<shevy>
oh
<hoelzro>
the class' initialize method takes precedence over the module's, right?
<shevy>
ohhhhhhhh
<workmad3>
shevy: when you include the module into the class, the class has in initialize instance method :)
<workmad3>
hoelzro: yes
<shevy>
yeah just realized that... hmm
<hoelzro>
so that module wouldn't work if you defined your own initializer
<shevy>
that's boggling the mind
<workmad3>
hoelzro: unless your own initializer called 'super'
Speed has joined #ruby
<workmad3>
shevy: I thought you hated modules though :P
und3f has quit [Quit: Leaving.]
<shevy>
workmad3 yeah
<shevy>
I think I hate subclassing even more though
mockra has quit [Ping timeout: 255 seconds]
<shevy>
I find these two ways very anti-thematic to each other
<Hanmac>
"ruby - full of things that shevy hate"
<shevy>
somewhat yeah
tonni has quit [Remote host closed the connection]
yxhuvud has joined #ruby
<workmad3>
I have stated in the past that including a module and inheriting a class have different meanings :P
<shevy>
I think there could be a much simpler ruby version possible
<shevy>
workmad3 when I think in terms of functionality, I feel a class is much more useful than a module
<shevy>
when I subclass, I make use of the parent class functionality
<shevy>
when I include a module, I make use of the module's functionality
vlad_starkov has joined #ruby
cantonic has quit [Read error: Connection timed out]
cantonic has joined #ruby
Know1edge has quit [Ping timeout: 255 seconds]
<shevy>
I don't think ruby will change much anymore
Know1edge has joined #ruby
indian has quit [Ping timeout: 264 seconds]
<workmad3>
shevy: remember though, you can only have one parent class for inheritance, but you can compose together as many modules as you want
<shevy>
yeah, that has annoyed me a lot in the past
<shevy>
I once wanted to make a biological tree-of-life
<shevy>
but eventually it just sucked... class Monkey < Animal
<workmad3>
shevy: ah... you've never had the fun of playing with multiple inheritance in C++ :P
<workmad3>
shevy: and figuring out if you need to do virtual inheritance from X in order to safely inherit from Y, or if you're going to hit the 'diamond of death'...
<shevy>
yeah, I learned only the very basics of C++
<shevy>
when I saw templates, I knew it was not a language for me
<workmad3>
templates are awesome :)
<workmad3>
turing complete functional language that operates in the compiler...
pskosinski has quit [Ping timeout: 255 seconds]
<shevy>
hmmmm
<workmad3>
error messages for templates are awful... but templates themselves are great :)
timonv has joined #ruby
<shevy>
hmmmmmmmm
<workmad3>
shevy: still, back to the point... multiple inheritance brings a mass of nasty problems with it... plain single inheritance gives very limited scope... single inheritance with multiple interface inheritance would mean a) ruby would require a concept of a formal interface, and b) tends to (IMO) encourage non-DRY code because you need to re-implement similar features in many classes
<shevy>
I must design the dumbest and simplest programming language that is still useful
<workmad3>
shevy: and so ruby has single inheritance with multiple mixins, which allows code reuse like a full MI system, but without the same sort of dangers
<workmad3>
shevy: but requires two separate concepts to handle inheritance and mixins
sebastorama has quit [Quit: Computer has gone to sleep.]
Emmanuel_Chanel has quit [Read error: Operation timed out]
<workmad3>
shevy: the dumbest and simplest programming language that is still useful has been 'designed'... PHP :P
tagrudev has joined #ruby
tagrudev has quit [Client Quit]
xbob has joined #ruby
<shevy>
hmm
<shevy>
it should be elegant too
<shevy>
I hate PHP syntax
<workmad3>
shevy: you're moving out of 'dumb' territory, and probably a bit out of 'simple' territory now :)
<shevy>
well simple in using it
<shevy>
$foo = 'bla';
<shevy>
I hate this
<shevy>
$foo->blablabla();
<shevy>
I hate this even more
<workmad3>
shevy: ever considered learning smalltalk?
<shevy>
workmad3, what I don't understand is... inheritance & mixin handling. Why can't this be integrated?
<shevy>
only a bit. I hated its syntax :)
<shevy>
I like the idea though
<workmad3>
shevy: inheritance and mixins can be integrated... but you end up with full multiple inheritance
<shevy>
syntax is the first thing I look at ... the Io language is nice, except that it uses that := or =: for assigning variables, that was killing me
<workmad3>
shevy: which introduces more problems, and of a class that are harder to conceptualise and solve
kjellski has joined #ruby
ph^ has joined #ruby
x0F has quit [Disconnected by services]
x0F_ has joined #ruby
<workmad3>
shevy: python allows multiple inheritance... it can be a real PITA figuring out what the hell is going to be called in that, and they've actually got a setup that collapses the inheritance tree unambiguously
x0F_ is now known as x0F
<shevy>
hmm
<shevy>
I hate explicit self in python
nyuszika7h has quit [Ping timeout: 260 seconds]
<workmad3>
shevy: everyone who isn't a pythonista does ;)
Cache_Money has quit [Ping timeout: 250 seconds]
<shevy>
I am going to come up with a good idea to solve the multiple inheritance problem once and for all
<workmad3>
shevy: ok... go and reinvent mixins :P
undersc0re is now known as Ethan
<workmad3>
shevy: seriously though... inheritance in OO has been done to death, it isn't interesting anymore
<shevy>
they all did it wrong so far
arturaz has quit [Remote host closed the connection]
<workmad3>
shevy: you're assuming that a mechanism that would satisfy you exists
<workmad3>
shevy: I'm pretty sure it doesn't
<workmad3>
shevy: but I'm all for you attempting... start by delving into what inheritance actually is, the ins and outs of different inheritance systems... be prepared to use some C++, python and java while investigating
<shevy>
ewwwwwwww
<shevy>
java
<shevy>
well, I'll dive deeper into python eventually
ananthakumaran has quit [Quit: Leaving.]
<Hanmac>
ruby mixins are better then php interfaces :P
<shevy>
pretty much everything is better than php
<workmad3>
shevy: java is a lingua-franca in this sort of investigation unfortunately
<workmad3>
shevy: and it's also a pretty good example of single-class, multiple-interface inheritance
<Hanmac>
shevy your last line is quotable :P
vlad_starkov has quit [Remote host closed the connection]
<shevy>
Hanmac one day I hope to have enough wisdom to have every of my lines become quote worthy :)
<workmad3>
shevy: playing around with the OO and MOP stuff in common lisp is also a good way to learn more OO intricacies
pskosinski has joined #ruby
timonv has quit [Remote host closed the connection]
mikepack has quit [Remote host closed the connection]
tonni has joined #ruby
monkegjinni has joined #ruby
<Hanmac>
Gurpartap, the site is feaky ... it does not work currect without javascript
workmad3 has quit [Read error: Operation timed out]
lkba has joined #ruby
mockra has joined #ruby
banisterfiend has joined #ruby
banisterfiend has quit [Read error: Connection reset by peer]
banisterfiend` has joined #ruby
twinturbo has joined #ruby
folivora has quit [Remote host closed the connection]
mockra has quit [Ping timeout: 255 seconds]
lkba has quit [Quit: Bye]
lkba has joined #ruby
Banistergalaxy has quit [Ping timeout: 272 seconds]
workmad3 has joined #ruby
Emmanuel_Chanel has joined #ruby
Russell^^ has quit [Quit: Russell^^]
niklasb has joined #ruby
Banistergalaxy has joined #ruby
darren has joined #ruby
areil has joined #ruby
workmad3 has quit [Read error: Operation timed out]
lxsameer has joined #ruby
lxsameer has quit [Max SendQ exceeded]
lxsameer has joined #ruby
lxsameer has quit [Changing host]
lxsameer has joined #ruby
br4ndon has quit [Quit: Lorem ipsum dolor sit amet]
pskosinski has quit [Quit: I've got a feeling there's a fish in the floor; I'd better squish it or he'll swim out the door; Sometimes they take me for a walk in the sun; I see my fish and I have to run]
tonni has quit [Remote host closed the connection]
br4ndon has joined #ruby
ananthakumaran has quit [Ping timeout: 244 seconds]
ananthakumaran has joined #ruby
naz has joined #ruby
hoelzro is now known as hoelzro|away
morfin has joined #ruby
mneorr has joined #ruby
morfin has left #ruby [#ruby]
darren has quit [Remote host closed the connection]
nedbat has joined #ruby
Morkel has joined #ruby
lxsameer has quit [Ping timeout: 240 seconds]
lxsameer has joined #ruby
arietis has joined #ruby
heftig has joined #ruby
lupine_85 has quit [Excess Flood]
mockra has joined #ruby
lupine_85 has joined #ruby
nateberkopec has joined #ruby
lkba has quit [Quit: Bye]
mikepack has joined #ruby
mikepack has quit [Remote host closed the connection]
heftig has quit [Ping timeout: 246 seconds]
Spooner has quit [Read error: Connection reset by peer]
mockra has quit [Ping timeout: 255 seconds]
SeySayux has quit [Read error: Operation timed out]
workmad3 has joined #ruby
Spooner has joined #ruby
lkba has joined #ruby
bairui_ has joined #ruby
workmad3 has quit [Ping timeout: 246 seconds]
_bairui has joined #ruby
bairui has quit [Ping timeout: 246 seconds]
jg has joined #ruby
<jg>
hi all, why does File.exists?(soft_link_path) return false and how can i check for soft link existence?
_0riginaI has quit [Max SendQ exceeded]
bairui_ has quit [Ping timeout: 244 seconds]
_bairui is now known as bairui
<apeiros_>
hu? i was going to answer that it is because no soft-link exists at soft_link_path, but it seems it indeed returns false even when it exists…
<apeiros_>
I'm pretty sure that was not always the behavior…
ZachBeta has joined #ruby
<apeiros_>
hm, 1.8.7 reports false too…
<jg>
FileTest.symlink?(soft_link_path) seems to do the trick
<apeiros_>
yeah, was going to say…
<jg>
but nonetheless i would expect File.exists? to work
<apeiros_>
but that's annoying behaviour… a symlink should be treated transparently as a file
<apeiros_>
and sure enough, File.read(soft_link_path) will read the file…
ecksit has joined #ruby
<ecksit>
morning
azm has joined #ruby
azm has quit [Changing host]
azm has joined #ruby
hunglin has joined #ruby
linoj has joined #ruby
jonathanwallace has joined #ruby
SeySayux has joined #ruby
heftig has joined #ruby
<ecksit>
let's say i am writing a method to check if the variable the method is bring used on is a weekend. how do i get the value of the variable into my method?
<ecksit>
i.e. t= Time.local(2012, 7, 28); t.is_weekend?
arkiver has joined #ruby
<banisterfiend`>
ecksit: buy a basic book on ruby, it'll tell u that on about page 5 ;)
<ecksit>
i have "the ruby programming language" by matz and davaid flanagan.
<Hanmac>
he dont need to buy a book, he only need to read it
<apeiros_>
ecksit: with t.is_weekend?, t is self. that means the method must be either in the Time class, or on t itself
_0riginaI has joined #ruby
<ecksit>
actually, new idea. i will have a look at the friday? method :p
mikepack has joined #ruby
mikepack has quit [Remote host closed the connection]
Gurpartap has quit [Quit: Page closed]
cloud|windoze has joined #ruby
Drager has left #ruby [#ruby]
liluo has quit [Remote host closed the connection]
Morkel has quit [Quit: Morkel]
zaydana has joined #ruby
ZachBeta has quit [Read error: Connection reset by peer]
ZachBeta has joined #ruby
linoj has quit [Quit: linoj]
<shevy>
hehe
<ecksit>
ok, still no luck.
tatsuya_o has joined #ruby
<Hanmac>
class Time; def is_weekend?; saturday? || sunday?;end;end
<Hanmac>
or something similar :P
<ecksit>
good job spoiling my fun. didn't even think of thta :(
resure has joined #ruby
<ecksit>
i was going through this giant idea of splitting strings getting the day, etc.
<apeiros_>
there's also wday
<ecksit>
fffuuuu
<ecksit>
stupid awesomeness.
Kwpolska has quit [Quit: Lost terminal]
<ecksit>
coming from php so i used to writing a class for simple shit like that
Kwpolska has joined #ruby
<apeiros_>
and that with a class like Time… which is arguably one of the weaker spots of ruby
_0riginaI has quit [Ping timeout: 264 seconds]
<Hanmac>
ecksit be happy that you are in ruby now ... you dont need to write php anymore :P
tatsuya_o has quit [Remote host closed the connection]
<ecksit>
can you use ranges for methods like friday?...sunday?
ZachBeta has quit [Read error: Connection reset by peer]
<apeiros_>
ecksit: won't make sense
<apeiros_>
they return booleans
ZachBeta has joined #ruby
<ecksit>
didn't think so :p
<apeiros_>
and true..false - what do you want with that?
<ecksit>
if they are all true, return a true
<Hanmac>
(5..6).include?(t.wday)
<apeiros_>
you can do t.wday.between?(4,6)
<apeiros_>
or the other way round as Hanmac shows
<apeiros_>
just be aware, sunday is 0
lxsameer has quit [Quit: Leaving]
<ecksit>
yep, ta
<apeiros_>
(you can easily shift that by doing (t.wday+6)%7 though
_0riginaI has joined #ruby
paulsherwood has joined #ruby
<Hanmac>
or when you very want the symbols: [friday?,:saturday?,:sunday?].any? {|sym| t.send(sym)}
mneorr has quit [Quit: Leaving.]
tatsuya_o has joined #ruby
<paulsherwood>
hi - i'm trying to build latest ruby on a basic Linux system, hitting "executable host ruby is required. use --with-baseruby option."
<paulsherwood>
is there a way to build ruby without ruby installed?
<apeiros_>
paulsherwood: never did it… but doesn't --with-baseruby which it suggest do what you want?
<paulsherwood>
apeiros_: possibly...
mockra has quit [Ping timeout: 272 seconds]
<ecksit>
just tried loading a ruby class into my irb instance (worked fine) however i got an error "NoMethodError: private method `is_weekend?' called for 2012-07-28 00:00:00 +1000:Time"
<ecksit>
my method definitely isn't marked as private though
<ecksit>
NoMethodError: private method `is_weekend?' called for 2012-07-28 00:00:00 +1000:Time
<apeiros_>
ecksit: where did you add the method? I mean in what file did you add it?
<ecksit>
desktop
<ecksit>
just created a file and loaded it (purely testing)
<apeiros_>
care to paste the file? and how did you name and load the file?
Foxandxss has joined #ruby
<apeiros_>
paste: gist.github.com, pastie.org or similar
<apeiros_>
you added a toplevel method. those are always private and they are in *all* objects. not just time objects.
<apeiros_>
you don't want that
<apeiros_>
class Time« def is_weeek_end? …
<ecksit>
ah, so you should extend the class?
<apeiros_>
urgs? where does that « come from?
<apeiros_>
class Time; def is_weeek_end? …
<paulsherwood>
apeiros_: sadl/win 2
* paulsherwood
fails in irssi
<apeiros_>
ecksit: the technical term is 'reopen the class'
<paulsherwood>
apeiros_: --with-baseruby is not a valid flag for make... am i missing something?
<ecksit>
got off irssi because i kept typing in the wrong convo's.
<apeiros_>
extend has its own meaning in ruby. see Object#extend
<ecksit>
will look into it
jg has quit [Remote host closed the connection]
<paulsherwood>
ecksit: what did you switch to? :)
<apeiros_>
paulsherwood: I googled a bit. seems --with-baseruby is just there to tell ruby where ruby 1.8 is installed. sounds silly…
<ecksit>
xchat
<zeen>
i want to create a method that is just to do with my Company model called update_promoted which will read the table and update 2-3 records. what is the best method for this? i looked at modules but it said they should be used for none-model centric logic. i also tried putting def self.update_promoted in the Model but I'm not sure if that's correct. and advise would be great
<Mon_Ouie>
btw, if condition then return true else return false is rather redundant — just the condition on its own does what you want
<paulsherwood>
apeiros_: i guessed that might be the idea... doesn't work for this situation, though :)
<ecksit>
mon_oule: trufact for now. i will need to handle the case later on though. thanks though.
timonv has joined #ruby
<ecksit>
i love the ease of ruby. none of this inconsistent crap.
heftig has quit [Ping timeout: 246 seconds]
<ecksit>
so for re-opening classes, should that be used whenever you plan on interacting classes like Time?
heftig has joined #ruby
Mon_Ouie has quit [Read error: Connection reset by peer]
<shevy>
no
<shevy>
use it rarely
<shevy>
if you distribute projects, then you'd often have to distribute your custom modifications as well
<charliesome>
zeen: in future, use gist, codepad or pastie instead. pastebin is awful
<zeen>
twice i did that, sorry guys :)
<shevy>
the code there looks a bit strange for ruby code
pskosinski has joined #ruby
<zeen>
yaa i have no idea what i'm doing
<zeen>
i'm just prodding things until they work and then rework them
akem has quit [Ping timeout: 272 seconds]
Ionic` has joined #ruby
<zeen>
i'm from cakephp so had to reunderstand the model classes.. which in ror seem to be the correct way :)
Russell^^ has quit [Read error: Connection reset by peer]
tatsuya_o has quit [Remote host closed the connection]
Russell^^ has joined #ruby
<shevy>
the first thing you should do is always get a clear picture of what you actually want to do
<shevy>
and why
<shevy>
you define a class method:
<shevy>
def self.update_promoted
<shevy>
and inside that class method, you ... try to call that same class method??
<shevy>
self.update_all(:promoted => false)
<shevy>
ah no
<shevy>
you try to call update_all
kjellski has quit [Quit: This computer has gone to sleep]
<zeen>
:)
<shevy>
but you invoke that 3x times
<zeen>
yaa, i see it as three queries
<zeen>
1 reset all previous, 2 promote last two, 3 promote mine
<zeen>
i guess 2nd and 3rd could be togehter but i was planning to do something more with this logic later
nedbat has quit [Ping timeout: 250 seconds]
timonv has quit [Ping timeout: 240 seconds]
paradoja has joined #ruby
<ecksit>
instead of re-opening a class, is applying singleton methods a better idea instead? so Time.is_weekend? instead of class Time ...
<charliesome>
ecksit: adopt a "look but don't touch" policy on all classes that aren't yours
timonv has joined #ruby
<ecksit>
so you would be suggesting creating all those within their own classes instead?
d3vic3 has quit [Quit: leaving]
nari has quit [Ping timeout: 272 seconds]
<Hanmac>
charliesome in ruby there is nothing like in C++ the final ... and when the developer realy wants to protect the classes why didnt he freeze them? so its the class editors fault :P
Hien has quit [Quit: leaving]
<shevy>
ecksit, it depends
zaydana has quit [Read error: Connection reset by peer]
zaydana_ has joined #ruby
<ecksit>
Hanmac: in relation to the previous question, which way would you go?
<shevy>
ecksit, if you think you are going to need something a few times, you can modify a core class
<shevy>
then bundle those modifications in one file, or in one directory
<Hanmac>
in this case, i would choise an instance method of Time
<shevy>
you could try use a singleton method but for some reason it is not often used
niklasb has quit [Ping timeout: 246 seconds]
<charliesome>
shevy: right but then developer B comes along and decides he also needs to modify a core class, uses the same method name and boom
<ecksit>
docuementation charliesome?
<shevy>
charliesome sure, that's what one gets when one has the feature of modifying core classes of a language. what would be needed is to restore to a tabula rasa state again cleanly
uris has joined #ruby
zaydana has joined #ruby
zaydana_ has quit [Read error: Connection reset by peer]
<charliesome>
ecksit: i'm mainly thinking of patches made in two unrelated libraries
<ecksit>
however, both of those methods are classified as re-opening a class though correct?
Hien has joined #ruby
Banistergalaxy has quit [Remote host closed the connection]
Hien has quit [Client Quit]
<shevy>
class String; def foo; end; end
<shevy>
this will always reopen
<shevy>
whoever came last, wins
Hien has joined #ruby
timonv_ has joined #ruby
<Hanmac>
charliesome do you use final in all of your C++ classes?
pskosinski has quit [Quit: I've got a feeling there's a fish in the floor; I'd better squish it or he'll swim out the door; Sometimes they take me for a walk in the sun; I see my fish and I have to run]
<charliesome>
i rarely use c++
<Hanmac>
or do you Freeze all your classes?
<shevy>
I heard people from Mono project whine about this, they said they hate that modifications other devs can do fucks them up (or rather, can fuck them up)
<charliesome>
no
<Hanmac>
so you do not forbit modification in your classes but tell us we should do? ... you are like america
<charliesome>
Hanmac: that analogy makes no sense
timonv has quit [Ping timeout: 264 seconds]
<charliesome>
i don't forbid modification to my classes, but I'm saying it's a really bad idea
<charliesome>
unless you can absolutely guarantee that you're the only one who's putting a certain method on a certain class, don't do it
liluo has joined #ruby
<charliesome>
and definitely don't do it if you're developing a library
julio has joined #ruby
ecksit has quit [Quit: Laters.]
arkiver has quit [Ping timeout: 252 seconds]
liluo has quit [Remote host closed the connection]
<Hanmac>
i use C macros in my libraries
pskosinski has joined #ruby
paradoja has quit [Ping timeout: 272 seconds]
tonni has joined #ruby
<banisterfiend`>
charliesome: monkeypatches which fix bugs are OK IMO, also a monkeypatch that adds a feature which would be the exact same as someone else's monkeypatch is OK too IMO (i.e Object#meta or Object#singleton_class)
dagnachewa has joined #ruby
tatsuya has joined #ruby
resure has quit [Remote host closed the connection]
<banisterfiend`>
charliesome: also monkeypatches which just add convenience methods to Object, where it doesnt matter too much if it's overwritten i would argue are OK too
resure has joined #ruby
<charliesome>
banisterfiend`: yeah you're right, but monkey patches that go and add non-trivial functionality are a no-no in my book
<banisterfiend`>
yeah
<banisterfiend`>
they can be really annoying
workmad3 has joined #ruby
_justin has joined #ruby
mockra has joined #ruby
nari has joined #ruby
julio has quit [Ping timeout: 244 seconds]
timonv_ has quit [Ping timeout: 250 seconds]
macmartine has joined #ruby
akem has joined #ruby
mockra has quit [Ping timeout: 240 seconds]
<otters>
cucumber's documentation is lousy
<Mon_Ouie>
Pretty much the only kind of monkey patches I use in my code is methods that can be overriden by different classes to define custom behaviour
<Mon_Ouie>
Kind of like Object#to_yaml
Tomasso has joined #ruby
phromo has joined #ruby
cloud|windoze has quit [Quit: Leaving.]
workmad3 has quit [Ping timeout: 244 seconds]
cantonic_ has joined #ruby
cantonic has quit [Read error: Operation timed out]
azm has joined #ruby
azm has quit [Changing host]
azm has joined #ruby
emmanuelux has joined #ruby
<otters>
wtf
cantonic_ has quit [Ping timeout: 246 seconds]
<otters>
I'm pretty sure it's impossible to define a username, password, and a port all at the same time when using Net::FTP
mikepack has joined #ruby
mikepack has quit [Remote host closed the connection]
<otters>
what the fuck
yugui is now known as yugui_zzz
krusty_ar has quit [Read error: Connection reset by peer]
Stalkr_ has joined #ruby
nedbat has joined #ruby
dr_diamond has joined #ruby
dr_diamond has quit [Changing host]
dr_diamond has joined #ruby
<otters>
what do I require to get net/ftptls?
paradoja has joined #ruby
maxmmurphy has joined #ruby
<shevy>
lol
<shevy>
otter!
* shevy
cuddles the otter
<shevy>
never heard of ftptls before
<shevy>
I dont think this is part of standard rbuy is it?
Russell^^ has quit [Quit: Russell^^]
<banisterfiend`>
shevy: talk to me, like lovers do
<shevy>
lol
<shevy>
so who of you uses yaml config files for ruby projets?
<banisterfiend`>
shevy: kyrylo does in pry-theme
beakerman has joined #ruby
twinturbo has quit [Quit: twinturbo]
<shevy>
cool
<otters>
waybe not
nateberkopec has quit [Quit: Leaving...]
ananthakumaran has quit [Quit: Leaving.]
ph^ has quit [Remote host closed the connection]
sepp2k has joined #ruby
maxmmurphy has quit [Quit: maxmmurphy]
ph^ has joined #ruby
Dreamer3 has quit [Read error: Operation timed out]
kaichanvong has joined #ruby
maxmmurphy has joined #ruby
bluenemo has joined #ruby
bluenemo has quit [Changing host]
bluenemo has joined #ruby
Dreamer3 has joined #ruby
sailias has joined #ruby
workmad3 has joined #ruby
leoncamel has joined #ruby
beakerman has quit [Read error: Connection reset by peer]
kvirani has quit [Remote host closed the connection]
conor_ireland has quit [Quit: conor_ireland]
pashamur has joined #ruby
vjacob has quit [Quit: This computer has gone to sleep]
<shevy>
no
nari has quit [Ping timeout: 250 seconds]
<shevy>
what is that
jrajav has joined #ruby
dr_diamond has quit [Quit: Bye !]
conor_ireland has joined #ruby
strife25 has quit [Quit: Computer has gone to sleep.]
dv_ has quit [Read error: Connection reset by peer]
dv_ has joined #ruby
i0n has quit [Ping timeout: 252 seconds]
lockweel has quit [Ping timeout: 255 seconds]
quest88 has joined #ruby
ttilley_off is now known as ttilley
Cache_Money has joined #ruby
workmad3 has joined #ruby
jjbohn has joined #ruby
<Hanmac>
shevy its an c derivate or something like that
adeponte has joined #ruby
kvirani has joined #ruby
Beoran__ has joined #ruby
workmad3 has quit [Ping timeout: 246 seconds]
timonv has joined #ruby
Beoran_ has quit [Ping timeout: 252 seconds]
davidokner has joined #ruby
luckyruby has quit [Remote host closed the connection]
conor_ireland has quit [Quit: conor_ireland]
dankest has joined #ruby
i0n has joined #ruby
<davidokner>
I'm trying to figure out the best way I could put "transfer from #{account_a.name} to #{account_b.name} is complete" in the Bank account example in the Pick Axe book. I want to add this feature.
<davidokner>
Is there a method I could use?
PaciFisT has joined #ruby
<davidokner>
It is on pg. 42 of the latest digital version of the Pick Axe book.
<Hanmac>
what method?
beneggett has quit [Ping timeout: 244 seconds]
<davidokner>
A method that will take the name of my variable and convert it to a string.
<shevy>
davidokner hmm?
<shevy>
def foo(i)
<shevy>
return i.to_s
<shevy>
end
<shevy>
foo(your_variable_here)
<davidokner>
to_s is the variable name?
<shevy>
note that #{} in "" strings calls .to_s
<shevy>
.to_s is a method name on class String objects
<shevy>
and in other classes who want a string representation
ananthakumaran has quit [Quit: Leaving.]
<davidokner>
to_s is not the contents of the variable?
<shevy>
it is, in string form
<shevy>
1.to_s # => "1"
<davidokner>
I don't want to the contents. I want the name of the variable.
VegetableSpoon has joined #ruby
<davidokner>
That might not be the final best way to do it though.
<shevy>
that info is lost
<davidokner>
Ok
<shevy>
x = 'foo'; call_method(x)
<shevy>
perhaps you can somehow tap into the ruby internals or the parse tree or something
jrajav has quit [Quit: The best darkness is strange and surprising]
<davidokner>
Do you know the example I'm talking about. Pg. 42 of Pick Axe bank example.
<davidokner>
There is probably a better solution.
<shevy>
I think I saw it once years ago
conor_ireland has joined #ruby
<davidokner>
I should probably build the Account class out more.
adeponte has quit [Remote host closed the connection]
<davidokner>
I want to put the account names of a transaction when a transaction is completed.
<davidokner>
I'm going to try adding an instance variable @account_name
<davidokner>
That make sense
<shevy>
dunno
<shevy>
:)
<davidokner>
I'm try some more.
<davidokner>
That info would be lost though, once you pass the variable name, but when you create a variable, you would think there would be a method to get the string of the variable name?
<shevy>
I do not think you can
<shevy>
you also should not need it
<davidokner>
That is probably not how it would be done anyway though, because you wouldn't be pulling that data from the variable name in the real world.
<shevy>
the variable refers to your object
<davidokner>
Right
<davidokner>
I only thought of that because the data was hard coded into the program in the example.
<shevy>
and your object holds the data that you need
<shevy>
what does that even mean
<davidokner>
In the real world it would be pulled from a database and I would store that into an instance variable int he Account class.
<shevy>
just provide a way to query that data
<shevy>
attr_reader :foo is the same as:
<shevy>
def foo
<shevy>
@foo
<shevy>
end
<shevy>
yeah davidokner
relix has quit [Quit: Connection closed for inactivity]
workmad3 has joined #ruby
<i0n>
http://pastie.org/private/vkzbsnd2hmefb9bz8zwqda hi i have this zip method, im trying to get a list of all files its zipping up without success. I'm not sure the syntax to do this I guess.
<otters>
at first I thought cucumber was dumb
<otters>
but then I became addicted to making tests pass
rippa has joined #ruby
dankest has quit [Quit: Leaving...]
<davidcelis>
cucumber is still dumb
<otters>
too true
digitalcakestudi has joined #ruby
Hanmac has quit [Ping timeout: 252 seconds]
chimkan has joined #ruby
Araxia has joined #ruby
<otters>
when you spend time debugging your tests
workmad3 has quit [Ping timeout: 244 seconds]
wallerdev has joined #ruby
wallerdev has quit [Client Quit]
wallerdev has joined #ruby
dankest has joined #ruby
nateberkopec has joined #ruby
savage- has quit [Remote host closed the connection]
Hanmac has joined #ruby
VegetableSpoon has quit [Quit: Leaving]
uris has quit [Ping timeout: 246 seconds]
zemanel has quit [Quit: Remote hottie closed the connection]
bluenemo has quit [Remote host closed the connection]
snearch has joined #ruby
tobago has joined #ruby
snearch has quit [Read error: Connection reset by peer]
vjacob has joined #ruby
greasegum has joined #ruby
vjacob has left #ruby [#ruby]
lkba has joined #ruby
cj3kim has joined #ruby
apok has joined #ruby
br4ndon has quit [Ping timeout: 252 seconds]
mucker has quit [Quit: leaving]
br4ndon has joined #ruby
CaptainJet has joined #ruby
ini has quit [Ping timeout: 246 seconds]
greasegum has quit [Ping timeout: 264 seconds]
br4ndon has quit [Ping timeout: 244 seconds]
sepp2k has quit [Ping timeout: 272 seconds]
sh4ring4n has joined #ruby
sh4ring4n has left #ruby ["Leaving"]
pskosinski has quit [Remote host closed the connection]
tatsuya has joined #ruby
snearch has joined #ruby
ProT-0-TypE has joined #ruby
drbawb has quit [Ping timeout: 240 seconds]
JetAway has joined #ruby
CaptainJet has quit [Disconnected by services]
JetAway is now known as CaptainJet
akem has quit [Read error: Operation timed out]
ThePicard has joined #ruby
LazyLucy has joined #ruby
<ThePicard>
Hey all, is there a way to bind method calls to functions in ruby?
<ThePicard>
like, in javascript you can do
<ThePicard>
var id = document.getElementById.bind(document);
xorgnak has joined #ruby
<Mon_Ouie>
I'm not sure what you mean
<Mon_Ouie>
Firstly, ruby doesn't have "functions" — only methods
<ThePicard>
Methods to other methods then, I suppose
<heftig>
meth = foo.method(:bar)
<jarred>
Are you asking if you can tell MRI, "When this method is called, call this other method!"
<ThePicard>
jarred: yes!
<ThePicard>
on a particular object though
<heftig>
ThePicard: take a look at delegate.rb
<heftig>
it's part of the standard library
<ThePicard>
like, when this method is called, call the get method on a hash, or something
<heftig>
def thismethod(*args); hash.get(*args); end
<Mon_Ouie>
I'm assuming you also want to call the original implementation of that method? Or do you want to define a method that does only that?
azm has quit [Ping timeout: 240 seconds]
<xorgnak>
ruby handles object creation through function very nicely actually. words = this is a string.split( )
sepp2k has joined #ruby
cj3kim has quit [Quit: Leaving]
<ThePicard>
heftig: that results in two method calls, not one though
sepp2k has quit [Client Quit]
koshii has joined #ruby
<xorgnak>
words.each { |w| puts w }
strife25 has joined #ruby
<xorgnak>
it's handy.
greasegum has joined #ruby
<ThePicard>
mhmm
Tomasso has quit [Ping timeout: 252 seconds]
<koshii>
Hey do you guys mind the occasional newbie question in here, or is there a better place for that elsewhere?
<koshii>
...If I promise not to ask Rails questions ;-)
<xorgnak>
and as far as I'm aware, object creation via function is faster and uses less memory.
<Mon_Ouie>
Beginners questions are pretty common really — there's definitely no problem with that
williamcotton_ has joined #ruby
<Mon_Ouie>
xorgnak: Faster than what?
<xorgnak>
everyone's a newbie of one sort or another.
<koshii>
xorgnak: Wise. :-)
williamcotton has quit [Ping timeout: 255 seconds]
williamcotton_ is now known as williamcotton
<Mon_Ouie>
You can't create an object without calling a method in Ruby anyway
<ThePicard>
i've looked at delegate
<xorgnak>
faster than creating the boject through method calls. I watched some youtube thing on functional ruby.
<ThePicard>
so then, there is no way of doing 'blah'.chars.map{|c| ahash[c]}
<ThePicard>
without the block?
<Mon_Ouie>
ThePicard: No. You can use method objects, but there's no real point in doing that.
<ThePicard>
Mon_Ouie: what's a method object?
pskosinski has joined #ruby
<xorgnak>
more like blah = chars.map {|c| ahash[c] } where chars is an array from a string that's been split into letters
dhruvasagar has quit [Ping timeout: 252 seconds]
<Mon_Ouie>
(You could do &ahash.method(:[]) instead of the block, but the latter is more idiomatic and… well… clearer)
<xorgnak>
what exactly are you trying to do?
<Mon_Ouie>
xorgnak: No, "blah".chars returns an Enumerator on the String's characters.
<Mon_Ouie>
(Which is lazy and thus better than getting an array for certain uses)
<ThePicard>
^this
<ThePicard>
Mon_Ouie: indeed, it is clearer
<xorgnak>
right you are. I just looked that up.
<ThePicard>
would the method object be faster at all?
<xorgnak>
appologies.
<ThePicard>
i know it's a pretty much pointless optimization
<ThePicard>
but I like to learn the internals of a language that I plan on using extensively
xorgnak_erc has joined #ruby
<Mon_Ouie>
ThePicard: I'm thinking creating it is actually slower than creating a block — but I never benched it
mrwalker has joined #ruby
<Mon_Ouie>
And also, "foo".split " " *is* a method call (there are no functions at all in Ruby), so… you can't say it's faster than using methods
<xorgnak_erc>
it'd be worth a test. the talk I saw made a pretty good case for functions in ruby.
tommyvyo has joined #ruby
<Mon_Ouie>
What people call functions, are just program-wide methods
<Mon_Ouie>
(usually, that is)
<ThePicard>
well, apparently ruby has a benchmark method, so it's time to find out =D
<ThePicard>
er
<ThePicard>
s/method/module/
tentimes has joined #ruby
mengu has joined #ruby
<ThePicard>
well, not really
<ThePicard>
because Method objects aren't callable
<ThePicard>
so, you'd have to have a block to call .call anyway
<ThePicard>
=/
<xorgnak_erc>
probably more functional in the sense of creating an object from the result of the method calls. obj = "".split... still creates obj from calling the methods.
<Mon_Ouie>
They are, you can use method.call(…)
<ThePicard>
Mon_Ouie: i mean
<ThePicard>
m = 12.method('+')
<ThePicard>
m(5)
<xorgnak_erc>
but try to explain that to someone who isn't exactly sure what a method is. functions we learn about in middle school math.
<ThePicard>
doesn't work.
<Mon_Ouie>
m.call 5
<Hanmac>
try m[5]
<Mon_Ouie>
That doesn't involve creating a block
<ThePicard>
in context of my original problem
<Mon_Ouie>
There's also m.(5)
<ThePicard>
'blah'.chars.map{|c| ahash[c]}
<xorgnak_erc>
m = 12.+(5)
<Hanmac>
look at this: ["a","b","c"].each(&object.method(sym))
strnx has quit [Excess Flood]
<Mon_Ouie>
"blah".chars.map(&ahash.method(:[]) — although that syntax does create a proc object out of the method object
<Hanmac>
hm yeah but it is not soo bad
<ThePicard>
what is a proc object?
<ThePicard>
also, & is what?
<Mon_Ouie>
When you turn a block into an object, you get a Proc
<ThePicard>
aha!
<xorgnak_erc>
that tells ruby to create a proc.
LazyLucy has quit [Read error: Connection reset by peer]
wintorez has joined #ruby
<Mon_Ouie>
foo(&obj) calls foo with obj as a block (obj gets converted to a proc by calling #to_prco on it)
wintorez has left #ruby [#ruby]
<xorgnak_erc>
bingo. also one of the cooler things on earth.
<Mon_Ouie>
def foo(&obj) — this stores the block that you get passed into a variable
duply has joined #ruby
jjbohn has quit [Quit: Leaving...]
<ThePicard>
hmmm
<ThePicard>
time to benchmark
<xorgnak_erc>
not sure how that would work, but I could certainly see being able to create a singleton method from a block using something similar to def mkmeth name, █ define_singleton_method name, block; end;
<xorgnak_erc>
and passing in pairs of names and blocks.
<Mon_Ouie>
The method you wrote is exactly the same thing as define_singleton_method though — so no need to write it :)
<ThePicard>
i think i need to read more docs about procs and method objects
<ThePicard>
that's what I'm getting from this XD
br4ndon has joined #ruby
havenn has quit [Remote host closed the connection]
skipper has joined #ruby
ryanf has joined #ruby
brianpWins has quit [Quit: brianpWins]
skipper has quit [Ping timeout: 246 seconds]
mehlah has joined #ruby
baroquebobcat has joined #ruby
baroquebobcat has quit [Client Quit]
apok has quit [Quit: apok]
digitalcakestudi has quit [Read error: Connection reset by peer]
mahmoudimus has joined #ruby
<ThePicard>
so, other than string.chars.map{|c| hash[c]}, how would you guys map every character in a string to a number?
tentimes has quit [Quit: If you think nobody cares, try missing a few payments]
<Mon_Ouie>
(well, more initialValue in Smalltalk I guess)
mockra has joined #ruby
<ThePicard>
mhmm
<ThePicard>
i'm too young to have even seen any code in smalltalk besides stuff on wikipedia =/
indian has quit [Ping timeout: 246 seconds]
<rking>
Every time I see Smalltalk syntax I drool, but then I wipe the drool off when I remember that they require trailing "."s (which act like trailing semicolons). Newline should terminate statements by default.
chimkan___ has joined #ruby
<rking>
ThePicard: Get Squeak, play with it for a weekend. It'll expand your mind.
<Mon_Ouie>
rking: But in Smalltalk a single method call can expand on more than a single line
<Mon_Ouie>
The most obvious example of that would be an ifTrue: … ifFalse: …
<rking>
Mon_Ouie: Hrm, it might get a bit gritty to work everything out cleanly, yes, but I'd say just backslash
<rking>
Hrm, right right
<rking>
Mon_Ouie: Indent level
<Mon_Ouie>
Yeah, that works for me
Ethan has joined #ruby
<ThePicard>
rking: i'll play with it =D
<Hanmac>
smalltalk was good for evolving but i dont see a reason why it sould still be used ... (there are better languages)
<rking>
ThePicard: I don't remember the good tutorials. It does help to follow a few so you can figure out which way is up in the UI, but once you start getting it you can just keep exploring.
chimkan has quit [Ping timeout: 250 seconds]
chimkan___ is now known as chimkan
<rking>
Hanmac: Are you referring to the system or the actual syntax/grammar?
cirwin has joined #ruby
chimkan has quit [Client Quit]
<Hanmac>
both of it ...
CaptainJet has quit [Ping timeout: 250 seconds]
w400z has joined #ruby
CaptainJet has joined #ruby
<rking>
Hanmac: The system is definitely something that takes adjusting, but the language itself, I'm not sure what there is to say is "better" now.
hoelzro|away is now known as hoelzro
MornStar| has joined #ruby
<rking>
It's so simple. For example the above ifTrue stuff, not even being builtin.
mahmoudimus has quit [Quit: Computer has gone to sleep.]
Bosma has joined #ruby
mockra has quit [Remote host closed the connection]
wvms has quit [Read error: Connection reset by peer]
wvms has joined #ruby
td123 has joined #ruby
ProT-0-TypE has quit [Quit: Leaving]
abdulkarim_ has joined #ruby
davidpk has quit [Quit: Computer has gone to sleep.]
s1n4_ has joined #ruby
lockweel has quit [Remote host closed the connection]
raul782 has joined #ruby
awarner has joined #ruby
s1n4_ has quit [Client Quit]
abdulkarim_ has quit [Quit: Ex-Chat]
s1n4_ has joined #ruby
strife25 has quit [Quit: Computer has gone to sleep.]
davidpk has joined #ruby
s1n4_ has quit [Client Quit]
havenn has joined #ruby
{aaron} has joined #ruby
mockra has joined #ruby
mockra has quit [Remote host closed the connection]
<{aaron}>
can anybody explain why i have to do this and whether there is a better way to access the rspec scope? http://pastebin.com/VVG2dce0
<{aaron}>
i know let defines a method...but i'm not sure how to access the receiver of that method from within a nested class context
<Mon_Ouie>
{aaron}: Because let defines a method in the context and whatever is self in RSpec tests
<Mon_Ouie>
So that method isn't accessible anymore when self changes
<Mon_Ouie>
(It may use method_missing to implement it, but whatever — still the same principle)
havenn has quit [Ping timeout: 246 seconds]
<{aaron}>
is there any less ugly way to refer to the method on the RSpec self other than defining a temp var ?
<{aaron}>
i'm looking for a singleton on the RSpec ExampleGroup class but I don't see anything that will get me a handle to it
SCommette has joined #ruby
<{aaron}>
i guess it just depends on RSpec implementation not Ruby
<Mon_Ouie>
Why not define a method yourself instead of using let?
gentz has quit [Ping timeout: 248 seconds]
gentz has joined #ruby
<{aaron}>
same problem actually
<{aaron}>
i.e. if i just change it to def rspec_var; "whatever"; end
<Mon_Ouie>
Don't define it there
<{aaron}>
same scoping issue
<{aaron}>
where would i define it?
<{aaron}>
you mean in the DSL class?
<Mon_Ouie>
Outside of hat block passed to describe
<Mon_Ouie>
that*
<{aaron}>
ahh, ok lemme see
SCommette has quit [Client Quit]
mikepack has quit [Remote host closed the connection]
<{aaron}>
yeah, ok, that works, but it turns out IRL I'm using RSpec 'double' which it can't find then :P
<{aaron}>
ok so i understand what is going on, i'll live with the tmp var
<{aaron}>
thanks for your help
dankest has joined #ruby
xorgnak_erc has quit [Remote host closed the connection]
xorgnak has quit [Remote host closed the connection]
xorgnak has joined #ruby
<{aaron}>
btw my tests do a lot of file IO and they are hella slow...i'm wondering if there is a common idiom for memoizing file data. i was thinking mmap although that doesn't look builtin. maybe just read the whole file into a byte array and treat as IO
<{aaron}>
or maybe just keep the same file handle open (tests are read only)
<fowl>
HELLA SLOW
<fowl>
where you from {aaron} i have a feeling that you are a cool cat
<{aaron}>
eh upstate ny
imami|afk is now known as banseljaj
<fowl>
bah nvm
<{aaron}>
synonymous with cool cat
<ryanf>
hmm. you're from upstate ny and you say "hella"?
<Mon_Ouie>
I'd argue that RSpec isn't known for being the fastest testing framework ever
tommyvyo has joined #ruby
xorgnak has quit [Remote host closed the connection]
sevvie has joined #ruby
xorgnak has joined #ruby
xorgnak has quit [Remote host closed the connection]
<Hanmac>
i0n because you do no result in your for loop
<Hanmac>
PS: and for-loops are outdated ... use enumerator fuctions for that
d3vic3 has joined #ruby
<Paradox>
Mon_Ouie, no, but its not the slowest
<Paradox>
that prize goes to the various java tests
<Spooner>
i0n : blah.map {|i| File.dirname(i) }
<Hanmac>
this works too: blah.map(&File.method(:dirname))
<Spooner>
Don't confuse the poor fellow :)
<i0n>
<--- mind blown
xorgnak has joined #ruby
xorgnak has quit [Remote host closed the connection]
Ethan has quit [Ping timeout: 246 seconds]
n8ji has joined #ruby
<i0n>
this is day 4 for me and its been a struggle but somethings are starting to make sense now
xorgnak has joined #ruby
<Mon_Ouie>
ThePicard: Did you try that benchmarks, I'm curious about the results? :p
xorgnak has quit [Remote host closed the connection]
<EstanislaoStan>
What is going on in this while loop? "while (line = file.gets)" Why are there parentheses and why isn't the = sign a == sign?
<Spooner>
Because it is "set line to the result of file.gets and then, if it is not nil, keep doing while"
<Paradox>
hmm, ok, a real question now. One of the projects i work on uses foreman, for starting a web server and some workers. We have to reboot the server on config changes, and i was trying to write a guard script, using guard-unicorn. But when i try to run this in foreman, it just ignores any changes
iamjarvo has joined #ruby
<Mon_Ouie>
As for the parens, they're not required
<ryanf>
yeah, although it is idiomatic to use parens if you are assigning
<ryanf>
to make it clear that you didn't intend for it to be ==
shadoi1 has joined #ruby
abdulkarim has quit [Remote host closed the connection]
gmci has quit [Read error: Operation timed out]
<Spooner>
EstanislaoStan : Though ideally, it should be file.each_line {|line| }, since then you don't use that horrible set-within-test business.
gmci has joined #ruby
xorgnak has joined #ruby
xorgnak has quit [Read error: Connection reset by peer]
fantazo has joined #ruby
<EstanislaoStan>
set-within-test?
<EstanislaoStan>
Oh, setting the variable in the while condition?
<Spooner>
Yes, sorry, condition is clearer than "test".
Ethan has joined #ruby
strife25 has joined #ruby
Tomasso has joined #ruby
abdulkarim has joined #ruby
<EstanislaoStan>
Ok, thanks for the explanation everyone.
xorgnak has joined #ruby
<fowl>
ruby <3s you
raul782 has quit [Remote host closed the connection]
gmci has quit [Read error: Operation timed out]
<Mon_Ouie>
Unless there's a method that takes a block, I really don't mind assignments within conditionals
xorgnak has quit [Remote host closed the connection]
xorgnak has joined #ruby
nedbat has quit [Ping timeout: 250 seconds]
TheShadowFog has quit [Quit: Leaving]
vlad_starkov has joined #ruby
awarner has quit [Remote host closed the connection]
joshman_ has quit [Quit: Computer has gone to sleep.]
xorgnak has quit [Remote host closed the connection]
br4ndon has quit [Quit: Lorem ipsum dolor sit amet]
gmci has quit [Ping timeout: 255 seconds]
SCommette has quit [Client Quit]
fantazo has joined #ruby
TheShadowFog has joined #ruby
maxmmurphy has joined #ruby
pencilcheck has quit [Remote host closed the connection]
uris has joined #ruby
gmci has joined #ruby
digitalcakestudi has joined #ruby
fowl has quit [Changing host]
fowl has joined #ruby
<fowl>
defendguin: there are 60 people in #rvm maybe they can help
jwmann has joined #ruby
maxmmurphy has quit [Quit: maxmmurphy]
linoj has joined #ruby
jjbohn has joined #ruby
thone has quit [Read error: Operation timed out]
Bosma has joined #ruby
brianpWins has joined #ruby
<davidokner>
Can you have a class variable and an instance variable by the same name and declare an attr_reader( :var) ?
thone has joined #ruby
<fowl>
davidokner: attr_reader won't touch the class var
<shevy>
davidokner, you must understand what attr_reader is
<shevy>
attr_reader :var is 100% the same as you doing this:
Speed has quit [Remote host closed the connection]
<shevy>
def var; @var; end
<Mon_Ouie>
And what class variables are, because I suspect you don't know that they are shared with subclasses
<davidokner>
It creates a method that returns the variable.
<davidokner>
I do know that
<Mon_Ouie>
the *instance* variable
<shevy>
yes but a method for that instance
<shevy>
davidokner, to answer your question, you can have both @var and @@var
<Mon_Ouie>
And it's also an instance method that gets defined
<shevy>
but the @@ really stink
<fowl>
dont use class var, use a class instance var
iamjarvo has joined #ruby
ghjk has joined #ruby
<davidokner>
shevy, I'm not asking that though.
<Hanmac>
me likes class instance variables too :P
<Mon_Ouie>
^ and for those, you can define another reader in the class' singleton class
<fowl>
class Foo; class << self; attr_reader :x; end end Foo.x will look for @x on the class Foo (not an instance)
manizzle has joined #ruby
<fowl>
not an instance of Foo*
<shevy>
it is always positively surprising how much fowl knows :)
<davidokner>
I don't think I know about class instance variables.
<Mon_Ouie>
They're just normal instance variables, which you set on a class object
<Mon_Ouie>
Which is possible simply because classes are objects too in Ruby
<davidokner>
What is wrong with class variables though?
<davidokner>
Oh, because you don't like that they are inherited?
<Mon_Ouie>
The fact they are shared with subclasses
<davidokner>
ok
<Hanmac>
in 99.9% of the cases you dont want sharing
raul782 has joined #ruby
<davidokner>
So if it isn't shared you wouldn't be able to access that class variable from the subclass though
cirwin has quit [Quit: cycl....ling!]
<davidokner>
Or would you?
<davidokner>
I'm just learning.
<Hanmac>
the Subclasses can have its own variables
<davidokner>
I'm getting confused. I probably should deal with that when I practice subclasses more.
<davidokner>
Right, but I might want the subclass to know how many things there are of the super class in general.
nedbat has quit [Ping timeout: 245 seconds]
<davidokner>
I'm practicing by expanding the banking example in the Pick Axe book to do more than the example does.
strife25 has quit [Quit: Computer has gone to sleep.]
<shevy>
davidokner you subclass. then you call super() to call the parent method
<davidokner>
I'm making it so it will tell you what accounts you transfered from and how much it just transfered. I also want to create an array of bank accounts, so I can then easy traverse it and print out the balances of all the accounts.
<davidokner>
Oh
<davidokner>
Ok, right
havenn has joined #ruby
fowl has quit [Ping timeout: 246 seconds]
<davidokner>
I'm using RubyMonk, The book of Ruby, The Little Book of Ruby, The Pick Axe Book and some tutorial web sites.
<davidokner>
I hope between all of that it will fill in any gaps in undestanding.
chson has quit [Remote host closed the connection]
<davidokner>
I've noticed that using multiple sources really helps.
akem has quit [Read error: Connection reset by peer]
akem has joined #ruby
havenn has quit [Remote host closed the connection]
ukd1 has joined #ruby
Spooner_ has joined #ruby
<shevy>
well
<shevy>
the only real way to learn ruby is by writing your own code from 0
greasegum has quit [Ping timeout: 244 seconds]
<davidokner>
I'm hiding the code and trying to write it from 0.
defendguin has quit [Quit: Leaving.]
Spooner has quit [Ping timeout: 246 seconds]
<shevy>
hehe
<davidokner>
I'm not ready to write my own programs yet.
<shevy>
that's the wrong attitude
<shevy>
you are always ready
<shevy>
the rest you will learn as you write
<davidokner>
Well I could make my own programs, but only with what I have learned so far.
<shevy>
there is not really one perfect way to write ruby code
<shevy>
in 2 years your style may be different and you will or could use different patterns anyway
<davidokner>
And I'm not very far yet, so I can't write very complicated programs.
<shevy>
that is good
<shevy>
complicated programs are horrible
<shevy>
I write only very simple, primitive programs
<i0n>
dirlocation = Dir.mkdir("/foo/bar") unless File.directory?("/foo/bar") .. this is not returning the result I would expect in irb?
<davidokner>
No, I mean I can't use many different programming concepts yet because I don't know how to use them because I haven't gotten very far in the books.
<shevy>
what result do you expect i0n
<i0n>
Its returning "No such file or directory" .. I would like it to create the dir.
<shevy>
davidokner, well many concepts are not easy to understand
<shevy>
procs and & syntax for instance
Nisstyre has joined #ruby
balki_ has joined #ruby
balki_ has quit [Read error: Connection reset by peer]
<shevy>
but you dont have to know everything in order to write useful things, really
<shevy>
you'll get better anyway
balki_ has joined #ruby
<davidokner>
shevy: Are you suggesting I don't continue with the book, but rather come up with ideas for programs and then try to find the specific answers in the books for problems as I encounter them?
<davidokner>
I was going to do a run-through of the books first.
<davidokner>
It has been a while since I have programmed too.
<davidokner>
I'm definately going to try to write programs to practice.
<davidokner>
After I get the ruby langauge I want to learn RoR.
<shevy>
davidokner the book is ok
<shevy>
but I suggest, write first. then continue reading the book
balki has quit [Ping timeout: 240 seconds]
<davidokner>
I'm writing programs as I learn new things in the book.
<davidokner>
I'm not just reading straight through.
<i0n>
hmm when specifying dirlocation= as a constant (if thats what its called) in a method argument, it chokes on syntax.
<Mon_Ouie>
You can't define constants from a method, and if you feel like you need to, then you shouldn't be using a constant in the first place
<Hanmac>
you can define constants in a method, but you should not do it
mahmoudimus has joined #ruby
<i0n>
def method(foo, bar="isthisaconstant")
<i0n>
?
<Hanmac>
thats only arguments, not constants ... ()
virunga has joined #ruby
<i0n>
oic thats called a default value
tonni_ has joined #ruby
nilg has quit [Read error: Connection reset by peer]
<Hanmac>
in ruby all constants begins (normaly) with a capital letter
shadoi has joined #ruby
jjbohn has quit [Quit: Leaving...]
<i0n>
So it is not proper syntax to do something like this for a method argument? def newmethod(foo, bar=Dir.mkdir(...) unless (....))
tonni has quit [Ping timeout: 246 seconds]
<Mon_Ouie>
You just need more parens
<Mon_Ouie>
(Dir.mkdir(…) unless …)
<Hanmac>
mmm when you dont get a syntax error then its proper :P
adamkittelson has quit [Remote host closed the connection]
<Mon_Ouie>
Although have complex expressions in a default value argument isn't really recommended
kvirani has quit [Remote host closed the connection]
sailias has joined #ruby
negval has joined #ruby
tommyvyo has joined #ruby
yugui_zzz is now known as yugui
negval has left #ruby [#ruby]
syamajala has joined #ruby
kah_ has joined #ruby
mehlah_ has joined #ruby
beneggett has joined #ruby
mehlah_ has quit [Client Quit]
<nikeita>
an instance var can be named like this -> display?
cirwim has joined #ruby
<nikeita>
or better with an attr_accessor: display?
<nikeita>
or better with an attr_accessor: :display?
zemanel has quit [Quit: Remote hottie closed the connection]
<hoelzro>
nikeita: if you *did* do that, I wouldn't make it attr_accessor
<hoelzro>
obj.display? = value seems funny to me.
mehlah has quit [Read error: Connection reset by peer]
jumpingcloud has joined #ruby
kpshek has joined #ruby
kpshek has quit [Client Quit]
<shevy>
nikeita you make too many :
<nikeita>
maybe an attr_reader: :display?
<shevy>
pls
<shevy>
try to reduce the amount of :
<Hanmac>
nikeita: i get: NameError: invalid attribute name `display?'
<nikeita>
yes sure.. sorry
<hoelzro>
that answers that
<nikeita>
maybe an attr_reader :display?
<shevy>
you can workaround it
<Mon_Ouie>
And both @foo? and foo?= are invalid
<nikeita>
now ok...
<shevy>
def display?; @display; end
<hoelzro>
but you can always do def display? ... end
<Mon_Ouie>
attr_reader :display; alias display? display
<shevy>
yeah or what Mon_Ouie showed
<Mon_Ouie>
Well, not really better
<shevy>
hehe
<Mon_Ouie>
But I do that with attr_accessor
hemanth_ has joined #ruby
<shevy>
would matz consider adding an attr_* that has a "?" at the end of its method name?
<shevy>
attr_cool :display
<shevy>
would make a display? method
<shevy>
hmm attr_query :display
<shevy>
attr_extended_reader :display
<shevy>
oh
<shevy>
attr_reader2 :display
syamajala has quit [Remote host closed the connection]
<shevy>
nah, those all suck...
<fowl>
whats wrong with attr_reader?
<nikeita>
attr_? :display
<jumpingcloud>
Hey, Does anyone know how to automate a keyed ssh session with password?
<shevy>
fowl it's fine, only when you want to add a ? query method... attr_reader :foo ... some_object.foo?
igotnolegs has joined #ruby
<fowl>
and instead of returning @display it should be !!@display
<hoelzro>
jumpingcloud: what kind of automation are you trying to do?
<fowl>
shevy: i meant `attr_reader?`
<shevy>
ah
<shevy>
hmm would this be legal syntax?
<jumpingcloud>
hoelzro: i just need to login to a system and have that system log into another system and run a few commands.
<Hanmac>
the "!" method could be overritten but this may be worst style ever :P
<bperry>
jumpingcloud: we do this in metasploit
<jumpingcloud>
hoelzro: bothe systems use shared keys with passphrases
<nikeita>
i do not understand why attr_reader :display? not work or is a bad practice
<hoelzro>
jumpingcloud: prompt for the first key at startup, and use agent forwarding?
<Hanmac>
other funny method names are "+@", "-@", "!@" , "~@"
<nikeita>
so the proper way is : def display?; @display; end; without attr_accessor
RubyPanther has quit [Quit: self.exit(:stage=>:left)]
<Hanmac>
information: 1 + -2 and 1 + - 2 are not the same in ruby
<bperry>
you would only be testing the existence of @display then right? not whether the value of @display is true or false
<bperry>
I could be wrong
kvirani has joined #ruby
<nikeita>
i need to check t/f
<bperry>
I could be wrong, but you may need to return @display == true or something
<nikeita>
call it @display_flagh
<nikeita>
ops
<jumpingcloud>
hoelzro: ssh-add is disabled on the first system. Isn't there a way to send keypresses? or a string to stdin
<hoelzro>
jumpingcloud: well, you *can* do it with a PTY
<hoelzro>
but those are not fun.
<hoelzro>
it's funny; someone just asked about this on #lua =)
negval has joined #ruby
negval has quit [Remote host closed the connection]
<jumpingcloud>
hoelzro: yeah i was looking into PTY, looks kinda tricky... I cant get my head around it.
tatsuya has joined #ruby
<nikeita>
bpeyy, why ? i can't simple return the boolean value?
d3vic3 has quit [Quit: leaving]
<jumpingcloud>
hoelzro: ha, yeah it'd be nice to be able to do this.
denis_ has joined #ruby
<hoelzro>
jumpingcloud: using ssh-add or password-less keys would be best, I'd say
<jumpingcloud>
in ruby,
<hoelzro>
there's also probably a libssh binding
<hoelzro>
or maybe you could leverage expect/PTYs
<jumpingcloud>
i know... ihave it working password-less, but I don't have root to this machine.. it's for work. I'm trying to automate some of my support tasks so i'll have more time to code at work ;)
odigity has quit [Ping timeout: 276 seconds]
<hoelzro>
hehe
<hoelzro>
so you're automating a root login via SSH?
<jumpingcloud>
hoelzro: shhh my boss would freak out.
<jumpingcloud>
but yeah totally..
<hoelzro>
O_o
<jumpingcloud>
it's not that bad
<nikeita>
bperry, it work without ==
<bperry>
cool :)
<bperry>
I wasn't sure how that would behave
kvirani has quit [Remote host closed the connection]
<nikeita>
basically it return already T/F
<bperry>
what id @display is nil?
<jumpingcloud>
hoelzro: it's all internal systems, it'll save me time doing it this way.
<bperry>
if*
<jumpingcloud>
hoelzro: =) do you not approve?
<hoelzro>
well, I don't
<hoelzro>
but I'm not you =)
<hoelzro>
I think requiring a password for this couldn't hurt
<Hanmac>
shevy do you know how to turn ruby commands into VM code points? (i mean that shows that the VM does?)
<Mon_Ouie>
bperry: nil is treated like false in conditionals
<jumpingcloud>
what if i wanted to cron it tho.
<bperry>
yep, I am aware
<bperry>
but I wasn't sure is nikeita was
devdazed has joined #ruby
<hoelzro>
jumpingcloud: then run the cronjob as root on the designated box
<bperry>
it may not be logic he was expecting
heftig has quit [Quit: leaving]
<nikeita>
just tested in irb
<Mon_Ouie>
Hanmac: puts RubyVM::InstructionSequence.disasm proc { |x| y = x + 2; puts y }
<nikeita>
if it is not set (nil) obj.display? return false
banisterfiend` has quit [Read error: Connection reset by peer]
heftig has joined #ruby
notVert has joined #ruby
<Mon_Ouie>
If you wanted to change the default, you wouldn't change the reader — you'd change the default value which you set in #initialize
linoj has quit [Quit: linoj]
<jumpingcloud>
hoelzro: yeah i get that, So I'll just keep it requiring the pass for now. But it'd be nice to know how to fully automate this.
<Hanmac>
Mon_Ouie: you could see the big diff between 1 + -2 and 1 + - 2 ;P
Vert has quit [Ping timeout: 252 seconds]
werdnativ has joined #ruby
cornholioz has quit [Quit: leaving]
whowantstolivefo has quit [Ping timeout: 260 seconds]
<jumpingcloud>
hoelzro: im going to explore your suggestion and check libssh, pty and expect. Have you checked out greenletters?
fowl has quit [Changing host]
fowl has joined #ruby
whowantstolivefo has joined #ruby
<hoelzro>
I haven't heard of it
<shevy>
not really Hanmac ... only example I have are things like:
<jumpingcloud>
hoelzro: it's promising to be a better solution than expect. And it looks nice but i'm getting errors trying to get it doing what i want.