ChanServ changed the topic of #ruby-lang to: Ruby 1.9.3-p125: http://ruby-lang.org | Paste >3 lines of text on http://pastie.org or use a gist
markit has quit ["Konversation terminated!"]
rdavila has joined #ruby-lang
rdavila has joined #ruby-lang
msisk has joined #ruby-lang
<rue> ReinH: No, AppleScriptObject
Brainix has joined #ruby-lang
codewrangler has joined #ruby-lang
senthil has joined #ruby-lang
dreieins has joined #ruby-lang
Telenull has joined #ruby-lang
rdavila has joined #ruby-lang
nofxx has joined #ruby-lang
shevy has joined #ruby-lang
ttilley has joined #ruby-lang
lele has joined #ruby-lang
<WillMarshall> How would I get the number of years different between two Date objects?
<_tca> you get the difference in seconds
<_tca> or you can compare the years directly #year
havenn has joined #ruby-lang
crudson has quit [#ruby-lang]
suborbital has joined #ruby-lang
tonesfrommars has joined #ruby-lang
t has joined #ruby-lang
nofxxx has joined #ruby-lang
Oloryn_lt2 has joined #ruby-lang
seanstickle has joined #ruby-lang
Nisstyre has joined #ruby-lang
macmartine has joined #ruby-lang
rohit has joined #ruby-lang
<rohit> ruby-core
dv310p3r has joined #ruby-lang
jtoy has joined #ruby-lang
cube526 has joined #ruby-lang
enebo has joined #ruby-lang
takaokouji has joined #ruby-lang
Clordio has joined #ruby-lang
nofxx has joined #ruby-lang
_santana has joined #ruby-lang
enebo has joined #ruby-lang
datanoise has joined #ruby-lang
shtirlic has joined #ruby-lang
spuk has joined #ruby-lang
elemarjr has joined #ruby-lang
senthil has joined #ruby-lang
Luxx_ has joined #ruby-lang
andrewhl has joined #ruby-lang
jaisoares has joined #ruby-lang
jaisoares has quit [#ruby-lang]
rdavila has joined #ruby-lang
divoxx has joined #ruby-lang
suborbital has quit [#ruby-lang]
gnufied has joined #ruby-lang
Kichael has joined #ruby-lang
stamina has joined #ruby-lang
yumike has joined #ruby-lang
gregf has joined #ruby-lang
mistym has joined #ruby-lang
rippa has joined #ruby-lang
wallerdev has joined #ruby-lang
ryanf has joined #ruby-lang
towski has joined #ruby-lang
brianpWins has joined #ruby-lang
nofxx has joined #ruby-lang
whatasunnyday has joined #ruby-lang
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
fgomez has joined #ruby-lang
nofxx has joined #ruby-lang
hagabaka has joined #ruby-lang
hagabaka has joined #ruby-lang
nofxx has joined #ruby-lang
slyphon_ has joined #ruby-lang
nofxx has joined #ruby-lang
dr0id has joined #ruby-lang
senthil has joined #ruby-lang
senthil_ has joined #ruby-lang
senthil_ has quit [#ruby-lang]
ankurgel has joined #ruby-lang
senthil_ has joined #ruby-lang
nofxx has joined #ruby-lang
savage- has joined #ruby-lang
byronb has joined #ruby-lang
`micro has joined #ruby-lang
gokul has joined #ruby-lang
nofxx has joined #ruby-lang
knu has joined #ruby-lang
jondot has joined #ruby-lang
yumike has joined #ruby-lang
nofxx has joined #ruby-lang
freedrull has joined #ruby-lang
nofxx has joined #ruby-lang
spectra has joined #ruby-lang
rippa has joined #ruby-lang
slyphon has joined #ruby-lang
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
Banistergalaxy has joined #ruby-lang
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
nofxx has joined #ruby-lang
rushed has joined #ruby-lang
whatasunnyday has joined #ruby-lang
ankurgel has joined #ruby-lang
Banistergalaxy has joined #ruby-lang
gix has joined #ruby-lang
Z33K|Lux has joined #ruby-lang
<WillMarshall> Hey. When I have a class State and a namespaced class HealthQuote::State
<WillMarshall> Iget "warning: toplevel constant State referenced by HealthQuote::State" when I run HealthQuote::State
<WillMarshall> How do I fix the namespacing here?
<heftig> WillMarshall: HealthQuote::State isn't defined when you reference it
<heftig> that's why it falls back to State
gregmoreno has joined #ruby-lang
<WillMarshall> heftig: Cheers
<WillMarshall> Iiiinteresting
<WillMarshall> Also weird
<WillMarshall> It should be loaded
yumike has joined #ruby-lang
rushed has joined #ruby-lang
SuperTa__ has joined #ruby-lang
Jade has joined #ruby-lang
rohit has joined #ruby-lang
nofxx has joined #ruby-lang
esad has joined #ruby-lang
My_Hearing has joined #ruby-lang
Teddy2steper has joined #ruby-lang
Teddy2steper has joined #ruby-lang
rohit has joined #ruby-lang
yumike has joined #ruby-lang
yumike has quit [#ruby-lang]
andrewhl has joined #ruby-lang
stamina has joined #ruby-lang
stamina has joined #ruby-lang
x0F__ has joined #ruby-lang
solars has joined #ruby-lang
turbolihis has joined #ruby-lang
kyrylo has joined #ruby-lang
kyrylo has joined #ruby-lang
ankurgel has joined #ruby-lang
<ankurgel> Hey! I am trying to make a method named gets_a (by modifying class String), so that I can do something like arr=gets_a (in place of arr=gets.split.map(&:to_i) #=>"1 2 3"=>[1, 2, 3] )
<ankurgel> for this i modified class String in something like: http://pastie.org/3731405
<ankurgel> but obviously this code is wrong. By this, I can do the operation only by this way: arr="".gets_a
<ankurgel> Please to help me in rectifying it. :)
<My_Hearing> Why do you define it in string if you don't want to call it on a string?
<ankurgel> My_Hearing: I initially thought to do that in class Array, but I don't know how to do '=' construct in that for it.
<ankurgel> [if it happens]
<ankurgel> Mon_Ouie: ^
zmack has joined #ruby-lang
thrcka has joined #ruby-lang
WillMarshall has joined #ruby-lang
ankurgel has quit [#ruby-lang]
<shevy> if you want a = method
<shevy> just do, inside class Array:
<shevy> def foo=(input)
<shevy> @foo = input
kiddorails has joined #ruby-lang
<Mon_Ouie> That's not he wants apparently
<Mon_Ouie> I think he just
<Mon_Ouie> wants def gets_a outside of any class
ankurgel has joined #ruby-lang
<ankurgel> Mon_Ouie: Sorry, got disconnected.
<ankurgel> Anyone replied anything on it?
JohnBat26 has joined #ruby-lang
yxhuvud has joined #ruby-lang
rohit has joined #ruby-lang
apeiros_ has joined #ruby-lang
deobald has joined #ruby-lang
mephux has joined #ruby-lang
tjadc has joined #ruby-lang
rue has joined #ruby-lang
kitallis has joined #ruby-lang
havenn has joined #ruby-lang
rippa has joined #ruby-lang
pbjorklund has joined #ruby-lang
vmoravec has joined #ruby-lang
|Vargas| has joined #ruby-lang
<shevy> ankurgel def foo=(input)
<ankurgel> shevy: yes, but in Class Array, what would I keep in left hand side of that setter?
<ankurgel> self?
<shevy> what left side
<ankurgel> class Array
<shevy> you mean within the body definition of the method?
<ankurgel> something=(value)
<ankurgel> #some operations
<ankurgel> end
<ankurgel> end
<shevy> within that method body you won't need self
<shevy> hmm
<shevy> you want a method called gets_a which resides in class String
<shevy> and this method should be synonymous to this:
<shevy> gets.split.map(&:to_i)
<ankurgel> yes
<shevy> so that is what should go into that method
<shevy> :)
<shevy> def gets_a
<shevy> gets.split.map(&:to_i)
<shevy> end
<shevy> profit!
<shevy> though I guess you want to make this available everywhere
<shevy> in which case, you'd have to define it outside class String
<ankurgel> clas1.9.2p318 :001 > class String
<ankurgel> 1.9.2p318 :002?> def gets_a
<ankurgel> 1.9.2p318 :003?> gets.split.map(&:to_i)
<ankurgel> 1.9.2p318 :004?> end
<ankurgel> 1.9.2p318 :005?> end
<ankurgel> => nil
<ankurgel> 1.9.2p318 :006 > arr=gets_a
<shevy> or, you do "foo".gets_a
<ankurgel> NameError: undefined local variable or method `gets_a' for main:Object
<shevy> of course
<shevy> gets_a is a method that resides within class String
<ankurgel> can't return array?
<shevy> you need a string object like "this one here" in order to call .gets_a on it
<ankurgel> ^yes, that will work.
<shevy> what do you mean with "can't return array", at this point in your code, the ruby parser does not know what is the method gets_a :)
<ankurgel> aah done! :)
<ankurgel> outside the class it is. shevy is awesome!
<shevy> well that was easy, I thought you wanted to do something difficult
<shevy> like
<shevy> use gets_a but inside a class
<shevy> hmm
<shevy> perhaps class Object
<shevy> or Kernel, I am not sure
<shevy> going to test it ...
<ankurgel> ok.
<ankurgel> I was actually trying to learn how to modify class methods to do something more interesting.
<shevy> ok
<shevy> it works
<shevy> now it is "globally" available
<shevy> but truthfully... I think if you dont have to extend core classes, in 90% of the time that is better than extend them
<shevy> unless you have a really clear advantage, like internal projects where you can then cut down a lot of code, or the code becomes much more readable
<shevy> ankurgel I carry a lot of my modifications to core classes in one directory
<shevy> I have ... array.rb dir.rb file.rb fixnum.rb hash.rb etc... all in one directory, modifying the respective class at hand
<ankurgel> shevy: there is a class named Object too? Never knew it.
<shevy> yeah it's quite the most important one
<ankurgel> irb -> Object.class #=> Class
<shevy> I actually think... but I could be wrong... if you start irb and do "def foo", then this becomes tied to class Object
<shevy> I am sad that I was unable to add to Kernel! :(
<shevy> class Kernel; def bla ...
<shevy> TypeError: Kernel is not a class
tekin has joined #ruby-lang
<ankurgel> shevy: Thanks. This is very helpful.
<shevy> without that, I could have sworn that Kernel is a class too
<shevy> but apparently it is not *pout*
<Gekz> Kernel is a module isn't it?
<Gekz> irb(main):001:0> Kernel.class
<Gekz> => Module
<ankurgel> The method like open belongs to Kernel right?
<Gekz> irb(main):002:0> module Kernel; def self.derp; 9; end; end => nil
<Gekz> irb(main):003:0> Kernel::derp => 9
<shevy> yeah Gekz
<shevy> though I have to say
<Gekz> NO YOU DO NOT
<shevy> I think if a user wants to extend a class OR a module anyway, why not allow a syntax style that would work for both :)
<Gekz> it's bad that people extend core objects anyway
<shevy> i.e. I dont really see the required reason to know the distinction between the two, before attempting to modify the behaviour
<shevy> yeah, I agree 80% to that
<Gekz> Object.to_json, kinda justified
<shevy> ewww
<Gekz> Kernel.test being redefined, not so much
<shevy> json
timbleck has joined #ruby-lang
<shevy> what surprised me once was that a method called y() exists
<shevy> in yaml :)
<Gekz> wtf, why
<shevy> not sure
<Gekz> good language
<Gekz> why is it a global
dr0id has joined #ruby-lang
<Banistergalaxy> It's not
<Banistergalaxy> Well you have to require it first
<shevy> hmm I am not sure if still exists in ruby 1.9.x
<shevy> but in 1.8, it is here:
<shevy> 1.8/yaml.rb: def y( object, *objects )
<Gekz> I just tried it in 1.9
<Gekz> it exists.
<shevy> hehe
<shevy> I am going to learn from this and do... def a ... def b ... def c ... to infinity!
<shevy> and everybody would be like
<shevy> "what the heck is k() doing..."
<shevy> and then i would proudly say
<shevy> "why, man, it is simple. It calls c() and l() and returns the combined result."
Synthpixel has joined #ruby-lang
Synthpixel has joined #ruby-lang
<shevy> hmm
<shevy> what if we would have a new keyword
Indian has joined #ruby-lang
<shevy> that could be used to extend both classes and modules and also un-extend these modifications
<shevy> modify Kernel
<shevy> modify Object
<shevy> hmm
<shevy> though I dont know how it would un-extend things again ... perhaps tied to the filename(s) it is done in?
<zenspider> what'd I miss?
<zenspider> shevy: my 'un' gem will unextend/uninclude modules
<shevy> oh
<erikh> I gotta admit, the modify keyword sounds appealing
<shevy> zenspider, on rubyforge?
<shevy> the un gem
<shevy> googling for "un" is weird
<zenspider> gem install un
<shevy> ah yes
<shevy> Successfully installed un-1.0.1
<erikh> banister had one too IIRC
Jade has joined #ruby-lang
<shevy> yeah, finding those treasures can be hard :(
<erikh> anyone know a little clojure in here?
<erikh> simply put, how bad am I doing? https://gist.github.com/5814afb600a5d0232300
<zenspider> I don't know clojure (yet), but that doesn't look like idiomatic lisp to me... shouldn't the args go on the same line as fn ?
<Boohbah> looks like lisp to me!
<erikh> that's the indentation they use in the manual
Synthpixel has joined #ruby-lang
<erikh> my lisp is pretty bad
<zenspider> recur looks neat
<erikh> I'm not afraid to admit it or anything; recur is just a tail-recursion instruction, dec is decrement and the others are probably obvious
<erikh> it's fib
<zenspider> http://clojure.org/special_forms#Special%20Forms--(recur%20exprs*)
<zenspider> hints that the args should be on the fn line
<zenspider> that said, it looks fine to me
<erikh> zenspider: there's a "koans" style site at 4clojure.org if you're interested in learning it in that style
<erikh> it's pretty neat, integrated repl and account tracking so you don't lose your spot.
<erikh> hm. you're right, I guess I blanked that.
<zenspider> cool. I'll have to try that
kitallis has joined #ruby-lang
Jade has joined #ruby-lang
futurechimp has joined #ruby-lang
kyrylo has joined #ruby-lang
kyrylo has joined #ruby-lang
Jade- has joined #ruby-lang
Jade- has joined #ruby-lang
srbartlett has joined #ruby-lang
judofyr has joined #ruby-lang
tjadc has joined #ruby-lang
francisfish has joined #ruby-lang
tekin has joined #ruby-lang
madcoder_ has joined #ruby-lang
d3vic3 has joined #ruby-lang
<Silex> how do I sort using two predicates in ruby? { |a,b| a.foo <=> b.foo && a.bar <=> b.bar } doesn't work
esad has joined #ruby-lang
<Silex> ah, sort_by { |s| [s.foo, s.bar]}
<Silex> nice
rue has joined #ruby-lang
pw_ has joined #ruby-lang
srbartlett has joined #ruby-lang
sandbags has joined #ruby-lang
rue has joined #ruby-lang
morozovm has joined #ruby-lang
m3nd3s has joined #ruby-lang
pw_ has quit [#ruby-lang]
woollyams has joined #ruby-lang
<andrewvos> ruby-lang, the place where questions answer themselves.
mssola has joined #ruby-lang
<shevy> that's what you get for a logical language!
<matti> LOL
<matti> andrewvos: I asked why I am not rich yet.
<matti> andrewvos: There was no answer ;/
<matti> andrewvos: I need to get my cash back [ look at shevy ... ]
<matti> ;d
<shevy> because you need to be a thief in order to get rich
<shevy> so my advice
<shevy> go into politics
<matti> shevy: No. I want my $5 back!
<matti> ;d
<shevy> pfffffft $5
<matti> Hahah
<matti> shevy: :))
<shevy> go to a bank and ask for a debt of $6
<shevy> :)
<matti> LOL
<matti> shevy: Go into politics...
<matti> shevy: I thought we were friends ;/
<matti> shevy: This is like a major offence ;p
<zenspider> Silex: (...).zero? && ... is how your write the former form
<andrewvos> I need to store a single value on a server. I will be storing this value every five minutes or so. This value doesn't have to be kept in a backing store.
<andrewvos> What's the easiest way ruby-lang?
<andrewvos> It needs to be on heroku, because <3 heroku.
<shevy> matti hehe
<andrewvos> (or if not on heroku, just somewhere else)
<shevy> matti that's politics. all friends on our way to the top... then we become enemies. :)
<andrewvos> Wait: http://openkeyval.org/
<matti> shevy: Hehe
<andrewvos> YAY
<Silex> zenspider: ah, good to know, thanks
judofyr has joined #ruby-lang
srbartlett has joined #ruby-lang
<zenspider> Silex: it's a lot uglier looking, but at least you have shortcutting
<Silex> I'll use the former for now, if performance becomes an issue I'll reconsider
<zenspider> yup yup
chendo_ has joined #ruby-lang
tbuehlmann has joined #ruby-lang
<andrewvos> Hmmm. If I curl ifconfig.me I get an ip, but using httparty I get the html page back... How can I just get the ip??
<andrewvos> Asssuming it's user-agent or something
<andrewvos> oh wait
<andrewvos> ifconfig.me/ip works
* andrewvos answers own question.
dbussink has joined #ruby-lang
rolfb has joined #ruby-lang
virunga has joined #ruby-lang
ankurgel has joined #ruby-lang
srbartlett has joined #ruby-lang
judofyr_ has joined #ruby-lang
hackeron has joined #ruby-lang
judofyr has joined #ruby-lang
judofyr_ has joined #ruby-lang
Radium has joined #ruby-lang
<andrewvos> gem list -> shows httparty
<andrewvos> file.rb requires "httparty"
<andrewvos> But I'm getting: require': no such file to load -- httparty (LoadError)
<andrewvos> What the hell is going on
<andrewvos> irb does the ssame
<andrewvos> Starting to feel like Defusal_ today.
<judofyr_> andrewvos: require "rubygems"?
Dreamer3 has joined #ruby-lang
batmanian has joined #ruby-lang
elemarjr has joined #ruby-lang
nazty has joined #ruby-lang
<andrewvos> judofyr_: Thanks :(
robertcarter has joined #ruby-lang
<rue> Yep, I see the similarity
riffraff has joined #ruby-lang
<andrewvos> rue: Don't agree with me :(
<robertcarter> Hi all, am getting undefined method `/' for nil:NilClass (NoMethodError) ... what does the `/' mean?
<andrewvos> robertcarter: You're trying to divide by nil?
<apeiros_> other way round
<apeiros_> you're trying to call / on nil
<apeiros_> i.e.: nil / 1 # <-- that'd raise that error
ankurgel has quit [#ruby-lang]
<robertcarter> hmm the plot thickens... thanks
havenn has joined #ruby-lang
Guedes has joined #ruby-lang
alset has joined #ruby-lang
<mlangenberg> I don't understand variable scoping in define_method. Is there a way I can do: https://gist.github.com/2310034, without resorting to #send?
havenn has joined #ruby-lang
amerine has joined #ruby-lang
anekos__ has joined #ruby-lang
<manveru> mlangenberg: define_method("#{name}?"){ instance_method_get("@#{name}") }
<manveru> err
<manveru> instance_variable_get :)
<mlangenberg> manveru: ah, thx. I was also thinking about that.
<mlangenberg> maybe this is quicker as it saves a method call.
<manveru> quicker is eval
havenn has joined #ruby-lang
<mlangenberg> really? Ugh.
<Drugula> name()
<Drugula> calls method
<manveru> eval("def #{name}?; !!#{name}; end")
<manveru> Drugula: no
<manveru> name is a string
<Drugula> oh, right
<Drugula> derp
<Defusal_> andrewvos, time to upgrade to 1.9?
<mlangenberg> I did not know eval runs faster, but I won't use it since it is so evil :P
<manveru> evil?
justinmcp has joined #ruby-lang
<manveru> you run the eval only once, the resulting method is faster
<apeiros_> manveru: why eval and not class_eval?
<manveru> what's the difference?
<apeiros_> good question, I was just wondering that…
<andrewvos> Defusal_: yeah probably
<Defusal_> andrewvos, have you used 1.9 before?
<manveru> looks like class_eval is a singleton method
<Defusal_> its like 10x faster
<manveru> so you can call it easier from outside
<Defusal_> i'd never be able to use 1.8 anymore
<manveru> andrewvos: RUBYOPT=-rubygems
<andrewvos> Defusal_: Yeah a lot. This is just some ubuntu box I'm doing a cron job on.
<shevy> sexual favours to an ubuntu box :(
anekos has joined #ruby-lang
rohit has joined #ruby-lang
<Defusal_> 1.9 is one of the first things i install on an ubuntu box :P
alset has joined #ruby-lang
shachaf has joined #ruby-lang
thorncp_ has joined #ruby-lang
kinabalu has joined #ruby-lang
robbyrussell has joined #ruby-lang
<andrewvos> Ok I' have given up.
<andrewvos> Back to ec2 where it's safe.
perryh has joined #ruby-lang
anekos has joined #ruby-lang
tdmackey has joined #ruby-lang
sj26 has joined #ruby-lang
amerine has joined #ruby-lang
esad has joined #ruby-lang
Jake232 has joined #ruby-lang
fayimora has joined #ruby-lang
havenn has joined #ruby-lang
riffraff has joined #ruby-lang
dejongge has joined #ruby-lang
sandbags has joined #ruby-lang
mark_locklear has joined #ruby-lang
havenn has joined #ruby-lang
judofyr has joined #ruby-lang
codewrangler has joined #ruby-lang
esad has joined #ruby-lang
batmanian has joined #ruby-lang
rippa has joined #ruby-lang
havenn has joined #ruby-lang
jarib has joined #ruby-lang
mistym has joined #ruby-lang
havenn has joined #ruby-lang
havenn has joined #ruby-lang
dous has joined #ruby-lang
woollyams has joined #ruby-lang
kiddorails has joined #ruby-lang
<kiddorails> Hey. How can I extract an mp3 from flv in ruby?
<kiddorails> Any library to support that?
<kiddorails> All I got was I can use external command (ffmpeg) to do that using 'fileutils'
Fullmoon has joined #ruby-lang
mstratman has joined #ruby-lang
Fullmoon has joined #ruby-lang
dv310p3r has joined #ruby-lang
judofyr_ has joined #ruby-lang
enebo has joined #ruby-lang
dv310p3r has joined #ruby-lang
seanstickle has joined #ruby-lang
mistym has joined #ruby-lang
tekin has joined #ruby-lang
scampbell has joined #ruby-lang
<canton7> kiddorails, there are ruby libraries which wrap ffmpeg
<Mon_Ouie> You don't need fileutuils to call external commands
<Mon_Ouie> fileutils*
<kiddorails> canton7: Mon_Ouie : Don't want to use ffmpeg or any outside dependency. How can it be done in ruby environment itself?
<kiddorails> I tried supplying flv to a var and pipe it character-by-character to output.mp3 file.
<kiddorails> mp3 of equal size gets generated, but obviously FAIL
futurechimp has joined #ruby-lang
<Mon_Ouie> kiddorails: If you don't want any external dependency that's going to be hard… I doubt anybody bothered to write a pure Ruby FLV/MP3 encoder/decoder
slyphon has joined #ruby-lang
<canton7> I doubt anyone would want to -- that sort of stuff is quite processor-intensive, and not wwhat ruby is good for
headius has joined #ruby-lang
gsav has joined #ruby-lang
Indian_ has joined #ruby-lang
Indian_ has joined #ruby-lang
jtoy has joined #ruby-lang
lele has joined #ruby-lang
elemarjr has joined #ruby-lang
heftig has joined #ruby-lang
<kiddorails> canton7: Mon_Ouie: And can Java etc do that?
lsegal has joined #ruby-lang
Synthpixel has joined #ruby-lang
<canton7> kiddorails, from what I can see, again, ffmpeg wrappers are the way to go
* kiddorails searches *ffmpeg wrappers*
<andrewvos> Yeah kiddorails just use ffmpeg. "Don't want any external dependencies" loses vs. "Getting shit done" every time.
<canton7> everythng I've ever seen that does audio/video transcoding uses ffmpeg
outoftime has joined #ruby-lang
kvirani has joined #ruby-lang
<kiddorails> andrewvos: :D True that. But what I am working on requires it to be from scratch. :(
divoxx has joined #ruby-lang
<andrewvos> kiddorails: Why?
bradland has joined #ruby-lang
mistym has joined #ruby-lang
tla has joined #ruby-lang
gregf has joined #ruby-lang
headius has joined #ruby-lang
gregf has joined #ruby-lang
msisk has joined #ruby-lang
<kiddorails> andrewvos: Task at hand.
<andrewvos> kiddorails: Uhhh. Nice answer there.
<kiddorails> andrewvos: If str = "/home/myacc/this_folder" . Why can't I execute Dir.chdir(str) to get in it?
<kiddorails> Though Dir.chdir("/home/myacc/this_folder") works fine.
slyphon has joined #ruby-lang
heftig has joined #ruby-lang
<canton7> kiddorails, short answer: you can. You've got a typo somewhere, or you're not giving us the whole picture
<kiddorails> oh it works. yes.
<kiddorails> canton7: Yes, sorry.
<kiddorails> :)
gregf has joined #ruby-lang
JEG2 has joined #ruby-lang
futurechimp has joined #ruby-lang
dfr|mac has joined #ruby-lang
jxie has joined #ruby-lang
savage- has joined #ruby-lang
robertcarter has joined #ruby-lang
Sailias has joined #ruby-lang
rippa has joined #ruby-lang
<cschneid> I have a few modules which need common functionality. My end classes want to 'include A', and 'include B', then also automatically have 'include Shared' happen. Modules can include other modules, but it seems to break the included hook to do classmethods
<cschneid> any blog posts or docs on how to make that work?
<cschneid> https://gist.github.com/9dda763654eee78779a0 - hopefully that's clearer than my rambly question
fayimora has joined #ruby-lang
havenn has joined #ruby-lang
tjadc has joined #ruby-lang
havenn has joined #ruby-lang
jaffachief has joined #ruby-lang
jtoy has joined #ruby-lang
datanoise has joined #ruby-lang
datanoise has joined #ruby-lang
datanoise has joined #ruby-lang
VladGh has joined #ruby-lang
rohit_ has joined #ruby-lang
fayimora_ has joined #ruby-lang
kitallis has joined #ruby-lang
Teddy2steper has joined #ruby-lang
apeiros_ has joined #ruby-lang
rowanu has joined #ruby-lang
gregf has joined #ruby-lang
fayimora has joined #ruby-lang
hirotoshi has joined #ruby-lang
rolfb has joined #ruby-lang
thrcka has joined #ruby-lang
burgestrand has joined #ruby-lang
tenderlove has joined #ruby-lang
rdavila has joined #ruby-lang
Synthpixel has joined #ruby-lang
wyhaines has joined #ruby-lang
jtoy has joined #ruby-lang
<outoftime> with Ruby 1.9 ordered hashes, is there a way to store a certain key/value pair at a certain position, like Array#insert ?
<apeiros_> outoftime: no convenient one
tjadc has joined #ruby-lang
<apeiros_> and no efficient one
<outoftime> apeiros_: so creating a new hash with just the key/value pair and then merging in the existing hash is probably as good as it's going to get?
<apeiros_> I think it's worse. I think you have to iterate over the whole hash, building a new hash and performing the insertion before/after the target key
<outoftime> apeiros_: oh right -- in this case I just want the new element to be first
<outoftime> apeiros_: so it's a little easier
Hexstream has joined #ruby-lang
Hexstream has quit [#ruby-lang]
<apeiros_> ah, yes
Indian has joined #ruby-lang
burgestrand has joined #ruby-lang
takaokouji has joined #ruby-lang
savage- has joined #ruby-lang
butchanton has joined #ruby-lang
ioga_wrk has joined #ruby-lang
fgomez has joined #ruby-lang
fgomez has joined #ruby-lang
hagabaka has joined #ruby-lang
hagabaka has joined #ruby-lang
sodani has joined #ruby-lang
butchanton has joined #ruby-lang
Teddy2steper has joined #ruby-lang
thrcka has joined #ruby-lang
<Defusal_> anyone got suggestions for making a method that takes multiple source paths, a destination dir and should take into account sub directories?
<Defusal_> the only thing i can think of is making it take a source directory, source file paths and a destination dir, and then slice the source directory off the source file paths to make the destination subpath
<Defusal_> i guess that is probably the best way :/
kyrylo has joined #ruby-lang
fgomez has joined #ruby-lang
brianpWins has joined #ruby-lang
erics has joined #ruby-lang
io_syl has joined #ruby-lang
Swimming_Bird has joined #ruby-lang
kvirani has joined #ruby-lang
Sailias has joined #ruby-lang
butchanton has joined #ruby-lang
willson has joined #ruby-lang
divoxx has joined #ruby-lang
<hagabaka> Defusal_: don't know what you mean
H2H has joined #ruby-lang
<Defusal_> hagabaka: if sources are '/source/dir/subdir/file' and '/source/dir/subdir2/file2', destination is '/dest/dir', it must copy to '/dest/dir/subdir/file' and '/dest/dir/subdir2/file2'
Asher has joined #ruby-lang
Indian has joined #ruby-lang
Indian has joined #ruby-lang
Asher has joined #ruby-lang
jensn has joined #ruby-lang
<hagabaka> Defusal_: sounds really arbitrary
senthil has joined #ruby-lang
wyhaines has joined #ruby-lang
jondot has joined #ruby-lang
publicvoid has joined #ruby-lang
havenn has joined #ruby-lang
macmartine has joined #ruby-lang
outoftime has joined #ruby-lang
H2H_ has joined #ruby-lang
deobald has joined #ruby-lang
heftig has joined #ruby-lang
crudson has joined #ruby-lang
divoxx has joined #ruby-lang
Morve-Ivan has joined #ruby-lang
Morve-Ivan has quit [#ruby-lang]
alexkane has joined #ruby-lang
havenn has joined #ruby-lang
crackity_jones has joined #ruby-lang
deobald has joined #ruby-lang
divoxx has joined #ruby-lang
headius has joined #ruby-lang
Skif has joined #ruby-lang
fayimora has joined #ruby-lang
<Defusal_> bougyman, you around?
<bougyman> si
brianpWins has joined #ruby-lang
brianpWins has joined #ruby-lang
brianpWins has joined #ruby-lang
<Defusal_> bougyman, you ever deal need to queue up deferred threads in EM?
<bougyman> sure
<bougyman> are you not on 19 with fibers and coroutines?
<Defusal_> i don't want to use fibers
<Defusal_> i assume EM.defer queues up blocks when the thread pool is in use
<whitequark> why not?
Synthpixel has joined #ruby-lang
<Defusal_> but that means that all future defers will be queued
<Defusal_> i want to create a seperate pool for file operations, so that they don't block all other commands
<bougyman> but you don't want to use fibers.
<bougyman> that means you need external job queue.
<bougyman> i recommend beanstalk.
<Defusal_> i thought EM::ThreadedResource was the answer, but looking at the implementation, it starts a new threads when initializing, so it would create a ton of threads instead of queuing stuff for a set pool of threads
<Defusal_> i don't need an external job queue...
<burgestrand> Defusal_: what is wrong with EM.defer?
<burgestrand> EM.defer is essentially a thread pool
<Defusal_> burgestrand, read up
<burgestrand> Defusal_: I don’t understand your point, which is why I ask
Fullmoon has joined #ruby-lang
<shevy> he just wants a hug
<shevy> how about some group hugs!
<Defusal_> burgestrand, if i have 5000 seperate file operations, such as cp commands queued, and then need to execute other commands, it will need to wait until all the cp commands complete before processing the other commands
<Defusal_> looks like i'll have to roll my own solution :/
<burgestrand> Defusal_: so, again, what’s wrong with EM.defer? mark up each of them with Defer, and the completion proc will check if all operations have completed and then schedule the next action to take after those
<Defusal_> burgestrand, you are clearly not reading...
dv310p3r has joined #ruby-lang
<Defusal_> nevermind :|
* burgestrand shrugs
* shevy hugs
<Defusal_> burgestrand, i mean that i do not want it to wait for a bunch of filesystem operations to complete before executing unrelated commands
<Defusal_> such as spawning a process
<Defusal_> so i need seperate thread pools
<RegEchse> 15:00:02 kiddorails | Hey. How can I extract an mp3 from flv in ruby? <- read that by accident; and it made me curious about the flv file format. So i looked it up and hacked together a few lines that essentially do what you want ;) http://pastie.org/3734406
<Defusal_> i must not have been clear the first two files :/
<Defusal_> looks like EM has nothing implemented for this, so i will have to roll my own thread pools
<burgestrand> Defusal_: you do know that if you do two thread pools it’ll be the same as using one thread pool but queueing the jobs in random order?
<RegEchse> kiddorails: well, actually that collects all mpeg frames. perhaps you'd have to read the sound format once and create an appropriate mp3 header ... (mplayer can play it, though, but it's just plain mpeg frames i guess)
futurechimp has joined #ruby-lang
qpingu has joined #ruby-lang
workmad3 has joined #ruby-lang
divoxx has joined #ruby-lang
<Defusal_> burgestrand, what?
<Defusal_> you mean if i use EM.defer for my thread pools?
<Defusal_> then obviously yes
<Defusal_> but that would be pointless
<Defusal_> if i have two seperate thread pools they will both be able to run at their max thread limit concurrently
<burgestrand> Defusal_: it’s still no different from using the EM thread pool with the same thread count as both your own thread pools count combined
<Defusal_> burgestrand, are you seriously still not following...
<burgestrand> Defusal_: if you just want an unordered threadpool (as opposed to executing each job in the same order they were queued in) wrap EM.defer in such a way that the completion proc takes a random job of the list of jobs and queues it
<Defusal_> i don't want an unordered thread pool...
<Defusal_> i want more than one ordered one
fgomez has joined #ruby-lang
<Defusal_> so that pool1 can be processing in order 10000 operations at its max thread limit at the same time as pool2 is processing 15 operations
<Defusal_> i can't be able more clear
<Defusal_> s/able/any
<shevy> today is just not a day for hugs :(
<Defusal_> i really don't know how you have not followed what i have been saying, because this is like the 4th time i have had to re-explain the same thing :|
butchanton has joined #ruby-lang
<burgestrand> Defusal_: I’m probably the one not being clear, we’re talking about the same thing but your solution is more complex and a bit unnecessary
<burgestrand> this is kind of common with us two though, I rarely understand what you are talking about and vice versa :d
kiddorails has joined #ruby-lang
<bougyman> why on earth wouldn't you use job queues for this?
kiddorails has quit [#ruby-lang]
<burgestrand> sounds like he wants to keep the jobs going in the same process
<Defusal_> burgestrand, in that case please try to explain clearly how i can do what i just explained with EMs current thread pool implementation
<burgestrand> and, well, actually…
<burgestrand> it’s one less dependency :)
<bougyman> and thousands of LoC in maintenance.
<burgestrand> bougyman: depends on what you are doing
<bougyman> sorry, i prefer leveraging work queues that are already proven.
<Defusal_> bougyman, because it is unnecessary complication for something that needs to callback to the reactor thread when done
<bougyman> Defusal_: it's guaranteed queuing of job.
<bougyman> i don't find that unecessary.
<bougyman> it even persists reboots or catastrophic fail of network.
<Defusal_> bougyman, and it fires a callback in my reactor thread how?
<burgestrand> Defusal_: two thread pools are essentially the same as using one large thread pool, with the one difference that you’re restricting a subset of the large pool to run only one kind of job
<bougyman> Defusal_: you have EM pop the work queue.
<Defusal_> bougyman, if there ever had to be a reboot, it wouldn't matter anyway
<Defusal_> as for network, it is local system operations
<Defusal_> bougyman, i don't follow, exactly how does the external process communicate with my processes?
<bougyman> this is likely the same app that uses ruby to try to supervise processes. it's already a loser, i think i'm out.
<burgestrand> Defusal_: it doesn’t, you put jobs in it on one end, and on another end you extract jobs from it and execute them
<Defusal_> burgestrand, explaining what i have already said 4 times is pointless now
<burgestrand> Defusal_: we don’t work together, it’s not you, it’s me, I want to break up
<Defusal_> :(
<burgestrand> we can still be friends
<burgestrand> but I want to try my luck with apeiros_
<Defusal_> burgestrand, thats my point, i need completion callbacks, which a job queue would be far from ideal for
<Defusal_> bougyman ^
butchanton has joined #ruby-lang
<bougyman> Defusal_: a job queue is perfect for completion callbaks.
<bougyman> i don't know what you're smoking, but I think I want some.
<burgestrand> Defusal_: yeah, it’s a bit of an odd thing, he’s suggesting that you put the jobs in an external work queue instead of having the queued procs in an array in memory
<burgestrand> or, not odd, just another approach
<Defusal_> bougyman, you have still not answered my question
<bougyman> Defusal_: i've answered it, you just don't want to accept the answer.
<bougyman> a work or job queue does exactly what you are specifying.
<Defusal_> burgestrand, its extra complexity, dependency and bloat
<Defusal_> but i still want to know how the callback is done
<burgestrand> Defusal_: I agree with you (somewhat), just trying to explain what he meant :p
<bougyman> with a consumer
<bougyman> in a work queue, you have a producer and a consumer.
<Defusal_> bougyman, using what interface does this job queue daemon tell my eventmachine application to fire a callback
<bougyman> that consumes jobs from beanstalk (a job queue) and serves all the dataness via websockets.
chimkan_ has joined #ruby-lang
hahuang65 has joined #ruby-lang
<Defusal_> after skimming over some of TCCs source i think i have a rough idea of how the interface works
<Defusal_> but it is definitely unnecessary complexity and another dependency
Sailias has joined #ruby-lang
<Defusal_> and if anything had to happen to the process that queued the job, the callback data would be invalid anyway, and so there could be inconsistencies in state
<Defusal_> burgestrand, and as for your statement about two pools restricting to a subset of one, i will have one last go at explaining; that is the point. if one is full, the other can continue. that is the whole purpose of wanting to have multiple pools.
butchanton has joined #ruby-lang
seanstickle_ has joined #ruby-lang
<Defusal_> burgestrand, come to think of it, being able to queue defer blocks at the beginning of the queue, instead of the end, would be sufficient
havenn has joined #ruby-lang
RickHull has joined #ruby-lang
RickHull has joined #ruby-lang
<burgestrand> Defusal_: for that last thing I would just wrap EM.defer in something, like this:
enebo has joined #ruby-lang
<burgestrand> Defusal_: … I can’t load any websites to paste it :p
<Defusal_> burgestrand, lol
<burgestrand> Defusal_: what you do is only queue up as much work as EM.defer can handle concurrently
<burgestrand> Defusal_: for EM.defer you can specify a proc to be run at the end of a job
<burgestrand> Defusal_: so, when you schedule your jobs using EM.defer, you use that proc to queue another job from the work queue you keep yourself
<Defusal_> burgestrand, i guess that can be done, but i can't think of anything wrong with just queuing jobs at the beginning of the pool instead
<Defusal_> that is a lot simpler to implement
<burgestrand> after that it’s just adding jobs to the right side of your work queue
<ironcamel> how do i get ri documentation for Array.map ?
<shevy> tried ri Array#map ?
<shevy> been years since I last used ri
<ironcamel> Nothing known about Array#map
<shevy> hmm
<Defusal_> burgestrand, why wouldn't you just monkeypatch EM and add a defer_before, or whatever named method
<burgestrand> Defusal_: the downside is that you have to maintain two thread pools instead of one, and if one of them runs out of work you’ll have a bunch of threads doing nothing
<drbrain> ironcamel: rvm?
<ironcamel> or any documentation, doesn't have to be ri
<burgestrand> Defusal_: because I don’t control EM :p
<ironcamel> but would prefer ri
<Defusal_> burgestrand, you don't even add methods to EM?
<RickHull> ironcamel: how did you install ruby?
<drbrain> ironcamel: did you install ruby using rvm?
<Defusal_> its pretty harmless, as long as you are sensible about it
<burgestrand> I don’t monkeypatch internals of things I don’t control if I can avoid it
<ironcamel> drbrain: no
wyhaines has joined #ruby-lang
<drbrain> ironcamel: gem install rdoc-data; rdoc-data --install
<Defusal_> burgestrand, fair enough :)
<ironcamel> drbrain: is collect an alias for map?
<shevy> yeah
<shevy> or vice versa
<shevy> ironcamel if you are fine with any docu, use the browser one :)
<drbrain> ironcamel: we can probably thank LISP weenies for both #map and #collect
<mistym> ironcamel: Most people here seem to like map better, I find collect more mnemonic. Down to personal taste.
<drbrain> #map for lyf‼
<RickHull> collect seems odd to me
<shevy> mistym well map is shorter, that's why I used it :)
<mistym> shevy: Fair enough. ;)
<mistym> Every chr counts.
<RickHull> if i'm collecting something, it's not clear im doing a transformation on it as well
<mistym> RickHull: I see what you mean. On the other hand, I usually think of it as collecting the return value (rather than #finding values in the original set).
<RickHull> ah, ok
<ironcamel> drbrain: thanks, i can see the docs now. why don't they include all the core docs with ruby?
<ironcamel> before i did that, ri Array#map wouldn't work
<drbrain> ironcamel: they do by default
<RickHull> it depends on how you installed ruby
<mistym> ironcamel: Are you using rvm? rvm doesn't build docs by default, but I think the standard ruby build does build the docs.
<drbrain> ironcamel: the method you used to install ruby overrode the default (unless you're using 1.8.7 where it's an extra `make install-doc`)
erics has joined #ruby-lang
<ironcamel> mistym: i'm pretty sure i'm using ruby from debian package
<ironcamel> 1.8.7
<shevy> oh yes typical debian :>
<ironcamel> but the weird part is part of the documentation is there
<drbrain> most packages of ruby ship documentation separately
<ironcamel> but not all of it
<shevy> but I am sure they bundled the docu in some package
<drbrain> in FreeBSD RDOC is disabled by default
erics has joined #ruby-lang
<ironcamel> until i did the doc-install thing
<mistym> ironcamel: If you don't mind my asking, why are you using 1.8.7?
twittard has joined #ruby-lang
<ironcamel> mistym: because that is what comes with my distro
<ironcamel> apt-get install ruby
<shevy> can you install the ruby docu with apt-get too?
<ironcamel> most distros default to < ruby 1.9 don't they
<Boohbah> if you have a distribution that provides an old version of ruby, get rvm or something and install a newer one
<Boohbah> debian-based ones do
<shevy> debian makes it a secret how to get the docu
<ironcamel> shevy: not sure. i don't know what package name to search for.
<shevy> yeah, I think they hate ruby users
<twittard> Hi everyone, I have a "just curious" question. If I have an array of numbers and I want to find the GCD, is there a ruby math library that does this already?
<ironcamel> shevy: shame on them!
<shevy> what means GCD
<ironcamel> greatest common divisor
<twittard> I mean, the algorithm is trivial, but I hate to code up a storm when some great math library is available
<ironcamel> same as greatest common factor
<drbrain> shevy: no, they don't hate ruby users, it's their policy to hate all the things
<shevy> hehehe
<Boohbah> yes!
<twittard> Right. The GCD of 25 and 30 is 5
<twittard> Boohbah: I know that, but it takes one argument
<shevy> ah ok... let's see ...
<twittard> So that does that for me
<twittard> But I'm guessing nothing exists for Array.
<twittard> Oh well, it's a fun algorithm to write, anyway.
<Boohbah> >> 99.gcd(3)
<Boohbah> => 3
<shevy> gosh
<twittard> It's fucking serenity compared to the shit I'm doing. So I should be happy.
<corsican> you can add a gcd method to Array
<ironcamel> twittard: the algorithm can be done in one line
<rippa> twittard: inject
<rippa> array.inject(:gcd)
<mistym> ironcamel: Seems kind of sad to me Debian is still distributing 1.8.7 by default. :( I mean, yes, some people are still deploying it, but it's also officially on an EOL schedule.
<rippa> though I'm not actually sure that it works
<twittard> not sure that'd work
<rippa> need tests
<twittard> yeah
<drbrain> rippa: :P
<ironcamel> mistym: 1.8 is EOL'ed or just 1.8.7?
<twittard> alright I'll have fun with this
<shevy> mistym it takes them +5 years for version changes
<shevy> ironcamel the whole 1.8.x
<mistym> ironcamel: 1.8.7 is the last in the 1.8 line. There isn't going to be another release.
<ironcamel> ah. good :)
<rippa> but it seems to work
<shevy> been the ruby version I liked the most too
<Boohbah> >> array = [3,6,9,12,24]
<Boohbah> => [3, 6, 9, 12, 24]
<Boohbah> >> array.inject(:gcd)
<mistym> ironcamel: Maintenance w/ bugfixes is going through June, then security fixes only through June 2013.
<Boohbah> => 3
<Boohbah> seems to work
<Boohbah> sorry for pasting :(
<Boohbah> rippa: awesome!
<shevy> hmm
<shevy> [25,30].inject(:gcd) # => 5
<shevy> indeed
<rippa> it should work if gcd(gcd(x,y),z) == gcd(x,y,z)
<shevy> that is actually the first time that the use of .inject I find beautiful
<rippa> what about factorial and summation?
<Boohbah> i used inject yesterday and it was ugly
<shevy> hehe
<RickHull> shevy: have you dipped your toes in the 1.9 water yet?
<shevy> RickHull I have a 1.9 installed here to test things
<shevy> I couldn't name anything I'd really desperately need from it though
<twittard> Actually, I think #reduce :gcd would work quite well
<RickHull> i believe it's an alias for inject ;)
Luxx_ has joined #ruby-lang
<twittard> Nice one. Writing tests to make sure.
wmoxam has joined #ruby-lang
<shevy> [25,30].reduce :gcd # => 5
<shevy> now what is better hmmmm
<twittard> I use reduce. People who use inject are Anti-Skub.
bjensen has joined #ruby-lang
<shevy> I think I hate both
MDmalLION has joined #ruby-lang
<shevy> but inject I see much more often... it is almost a foe I know
<RickHull> if inject works, there is no chin-scratching needed to determine if reduce will ;)
<RickHull> oh, i think i misunderstood
<twittard> why do you hate skub, RickHull?
<shevy> because he is anti-skub
<twittard> monster
<RickHull> what is skub, pray tell?
<bjensen> what is the ruby equivalent of the rails method #present?
<twittard> click link
<shevy> what is #present doing?
<Boohbah> twittard: yeah, inject and reduce are synonymous
* shevy clicks twittard
<twittard> bjensen: it calls empty? if self responds to empty?
<senthil> bjensen: !nil? & !blank? I think
<twittard> otherwise it returns !nil?
<bjensen> ah its nil and blank..
<bjensen> no blank doesn't exist
<bjensen> for string
<shevy> rails is wicked magic
<twittard> ActiveKetsup makes everyone lazy
<senthil> bjensen: !nil && !empty?
<twittard> Ketchup, fine
<bjensen> respond_to?(:empty?) ? empty? : !self
<bjensen> hmm
dv310p3r has joined #ruby-lang
<bjensen> senthil: right..but Fixnum does not respond to empty
<bjensen> The reason I ask is before I want to write fast rspec tests that does not depend of rails..
<shevy> rails changes people
<MDmalLION> are lynda rails tutorials anygood?
Swimming_Bird has joined #ruby-lang
* apeiros_ is confused…
<apeiros_> 20:47 burgestrand: but I want to try my luck with apeiros_ <-- what was that all about? o0
judofyr has joined #ruby-lang
<apeiros_> and of course, I miss burgestrand by 2 minutes to ask him…
deobald has joined #ruby-lang
jmontross has joined #ruby-lang
<jmontross> how to grab first 100 chars in astirng?
<apeiros_> str[0,100]
<shevy> hmm
<shevy> astirng[0,100]
<apeiros_> hehe
fgomez has joined #ruby-lang
<jmontross> or string.slice(0..99)
andrewhl has joined #ruby-lang
<jmontross> maybe the array method is nicer.
<shevy> oh man
<shevy> ("abc " * 200).slice(0..99)
<shevy> hmmm
<shevy> ("abc " * 200)[0,100]
<shevy> I like the one without .slice more
<apeiros_> jmontross: you're aware that slice and [] are aliases, yes?
kinabalu has joined #ruby-lang
<Defusal_> jmontross, why string.slice(0..99) over string[0..99]?
<Defusal_> oh, apeiros_ already mentioned that :P
<jmontross> i am aware… that's why i suggested that maybe it was nicer
z3r00ld has joined #ruby-lang
<jmontross> i just didn't think of it… i asked the question then wanderd off to the string documentation
<apeiros_> [] is more commonly used than slice. but that's a personal taste thing.
<jmontross> [] is more simple
<jmontross> i'll switch it
<Defusal_> yeah i havnt really need slice used
<Defusal_> i used slice!
<Defusal_> *use
<Defusal_> i also have pretty much never used [n,n]
<jmontross> in rails i really get confused about where to put functionality sometimes… i have a view where i want to do something, but i try to move the code into application helper and the hpricot gem is not available there
<Defusal_> i find just using a range more consistent
Indian has joined #ruby-lang
<Defusal_> jmontross, no expert on rails, but gems should be available anywhere
rdavila has joined #ruby-lang
<z3r00ld> hi, i am trying to rescue a function which exits if there is an error in a for loop, but when first loop gets executed and encounter an error it just exit and does not get rescued, is there any way i can have the for loop running even with the errors in function
<z3r00ld> in short i m running a for loop on a function and trying to rescue any error, but when an error encounters it just quit
<drbrain> loop do begin … rescue SomeException; handle_it; end; end
<Boohbah> (1..100).inject(&:+)
<Boohbah> so, what is the ampersand for?
<andrewvos> Boohbah: lulz
<Boohbah> andrewvos: lulz
<drbrain> Boohbah: it's not needed
<drbrain> inject works fine with a symbol representing a method these days
<andrewvos> drbrain: Whoa didn't know that :/
<Boohbah> drbrain: ok, i found that on the web
<Boohbah> thanks
mrb_bk has joined #ruby-lang
<Defusal_> drbrain, i pretty much never use inject, so i wouldnt know that, does that go for all such methods?
<Defusal_> i use symbol to proc a lot
<drbrain> Defusal_: I think inject is special
<Boohbah> ahh Symbol#to_proc i see
havenn has joined #ruby-lang
<jmontross> Defusal : I thought so too… but "undefined method Hpricot"
<Defusal_> drbrain, ah i see
<jmontross> restarting rails app… maybe it needs be restarted when adding gems into applciation helper
<jmontross> but perhaps this should not be in this spot...
<z3r00ld> drbrain: thanks, i was putting begin - rescue at wrong place
<Boohbah> so, can anyone recommend the pickaxe book, 3rd ed.
<Defusal_> jmcphers, gem classes are on the top level namespace, so they are available everywhere, unless the gem is not loaded correctly (or maybe not yet, at that point? i know rails does some lazy loading stuff)
<Boohbah> is it any good?
<Defusal_> jmcphers, you need to restart ruby when adding new gems to your gemfile
<Defusal_> but not when using gems that are already added
<MDmalLION> anyone have a good example of classing']
<z3r00ld> is return the last line that gets read in a function
<Defusal_> what your definition of 'classing'?
<Defusal_> z3r00ld, unless the return keyword is used before that, yes
<MDmalLION> I know how to make one and call the methods from it, but I want it to run a specific method
<Defusal_> err, you are going to need to pastebin an example
<MDmalLION> kk
<MDmalLION> how do I make this more functional, like drug dosages, contraindications
postmodern has joined #ruby-lang
workmad3 has joined #ruby-lang
slyphon has joined #ruby-lang
babinho has joined #ruby-lang
bglusman has joined #ruby-lang
<shevy> take the red pill MDmalLION
<MDmalLION> it has piperazines
<MDmalLION> i refuse
<shevy> you must instantiate ACEInhibitors
<shevy> your_drug = ACEInhibitors.new
<shevy> your_drug.lisi
<MDmalLION> after all methods of after each one
outoftime_ has joined #ruby-lang
<MDmalLION> or*
H2H has joined #ruby-lang
<shevy> that depends what you need to do
<shevy> if you must call all methods, it is better to bundle them into a new method
<uniqanomaly> MDmalLION, youre trying to build something specific?
<shevy> def run_all
<MDmalLION> yes
<shevy> cat
<shevy> enal
<shevy> lisi
<shevy> end
<shevy> and then...
<shevy> your_drug.run_all
<MDmalLION> a website that has all the material for an exam
twittard has quit [#ruby-lang]
<shevy> then it may be better to put that into a yaml file
<shevy> and use your ruby class to load the yaml file and fetch the required questions
<shevy> class Exam
<shevy> def initialize
<shevy> load_yaml_dataset
<shevy> and so on
<MDmalLION> mmm
bjensen has joined #ruby-lang
<MDmalLION> reading up on yaml
qpingu has quit [#ruby-lang]
<shevy> yaml is quite easy
<shevy> in your ruby code, you must do
krz has joined #ruby-lang
<shevy> require 'yaml'
<shevy> to load a yaml file you must do:
<shevy> YAML.load_file("location/to/your/yaml/file.yaml")
<shevy> or better assign it to a variable
<shevy> data = YAML.load_file("location/to/your/yaml/file.yaml")
<shevy> and then continue to use it
<shevy> if your exam is just question: answer format
<shevy> you should be able to do this:
<sodani> question - when you do gem install <gem name>, where does this install from?
<shevy> - "blabla drug has what effect? It kills rabbits."
<shevy> or actually, you can also store in a .rb file, it's not a huge difference if your questions are simple
<jmontross> sodani : gem sources
<jmontross> is probably your only gem source
<drbrain> also, $PWD
<shevy> sodani it fetches from remote server by default
<jmontross> remote server is that rubygems.org...
<jmontross> remember when git hosted gems for a bit?
<sodani> and gems can generally be installed from either rubygems or github correct?
<jmontross> i think github stopped doing that… maybe im wrong.
<yorickpeterse> Yeah, they stopped doing that quite a while ago
<jmontross> looks like they still maintain a list… i wonder if they just stopped adding
<yorickpeterse> They probably have
<Banistergalaxy> jmontross: what conflict dodd you have with pry that you removed it
<Banistergalaxy> Did
<sodani> jmontross: but you can still specify a github repo for each gem in your Gemfile if you wanted to
<Boohbah> avg = scores.reduce(:+).to_f / scores.size
<Boohbah> much better :)
qpingu has joined #ruby-lang
<apeiros_> scores.inject(:+).fdiv(scores.size)
krz has joined #ruby-lang
dr_bob has joined #ruby-lang
hahuang65 has joined #ruby-lang
woollyams has joined #ruby-lang
<Boohbah> apeiros_: thanks :)
<RickHull> also, you could name your variable mean instead of avg, putting me one step closer to my pedantry merit badge
<Boohbah> mean,median,mode
<Boohbah> can all be considered averages?
<RickHull> that's what i learned in school
<Boohbah> yeah, i did too
<Boohbah> i just forgot
Swimming_Bird has joined #ruby-lang
<Boohbah> thanks!
<RickHull> cheers!
<Boohbah> do you like my method?
<apeiros_> that could be done easier
<RickHull> it's quite a piece of work
<apeiros_> or shorter
<RickHull> oh, nevermind, my browser window was too narrow
<RickHull> the formatting looked terrible ;)
<Boohbah> yes, how can i improve it?
<apeiros_> allso, isn't E missing?
<RickHull> american-ism, i think
<apeiros_> *also
<Boohbah> yeah, we don't have E grades in the US
<RickHull> definitely E is rare/nonexistent in USA. probably other places
<apeiros_> funny
<Boohbah> do you have them in europe/somewhere else?
<apeiros_> we don't use letters
<apeiros_> we grade 1-6
<RickHull> Boohbah: i like your method. it's clear. my only concern is range overlaps, but i forget exactly how they work
<yxhuvud> we graded 3-5 when I were at university.
<apeiros_> Boohbah: "FFFFFFDCBA"[grade.div(10)]
<RickHull> i would probaby raise(InvalidGrade, grade.to_s) in the else
<apeiros_> RickHull: he uses ..., which is good
<apeiros_> RickHull: also his order would prevent a problem anyway.
<RickHull> yeah, presumably a 70 is still a C
aroop has joined #ruby-lang
<Boohbah> i think my range operators are ok
gregmoreno has joined #ruby-lang
<Boohbah> apeiros_: shorter, but not immediately obvious to me :)
* Boohbah reads div doc
<apeiros_> integer division
<apeiros_> could do (grade/10).floor too, but I expect core knowledge from a reader of my code.
<Boohbah> ok, i see how it works
<Boohbah> thanks again apeiros_ , RickHull :)
thone has joined #ruby-lang
aprescott has joined #ruby-lang
benanne has joined #ruby-lang
<aprescott> suppose you've got flat markdown files storing blog post content and you want to turn the posts into an atom feed, which contains created-at and updated-at timestamps. other than storing those timestamps as metadata values at the top of each file, can anyone think of a really neat solution?
<aprescott> using the filesystem is obviously out
<drbrain> aprescott: doesn't the filesystem store both timestamps (usually)?
<aprescott> drbrain: what happens if the modified time changes but semantically nothing has actually changed?
<aprescott> drbrain: or what if you copy stuff around and the creation time gets altered? you don't want to spam the feed with false changes
<aprescott> this problem has been bugging me for months
byronb has joined #ruby-lang
dr_bob has quit [#ruby-lang]
<drbrain> why would you copy stuff around? I thought URIs didn't change
<aprescott> if it were an rss feed you could get around the problem by just abstracting out the rss feed entries from the actual data in the data store
<drbrain> well, cool ones, anyway
<aprescott> :)
<aprescott> idk suppose you change the location of your files
<aprescott> semantically the content is the exact same, but the timestamps on the file in the filesystem have all been updated
<drbrain> … is this something your VCS could handle?
<aprescott> the vcs is git which doesn't track that data, it only cares about content
<drbrain> I would try to avoid changing links on people
<aprescott> every time it touches a file it updates the modified time
<heftig> looking for a storage backend for my bot. any suggestions?
<erikh> hey, if someone sees an imperator, can you have him ping me?
<aprescott> the links stay the same, the files are served through a very thin wrapper on the directory, rendered as html
<drbrain> aprescott: you mean you can't ask git for the last commit time?
<drbrain> nor the first commit time?
RickHull has quit [#ruby-lang]
savage- has joined #ruby-lang
<aprescott> so the URIs will stay the same, because the content is independent of the filesystem structure
<aprescott> drbrain: it's possible in theory but then you're tying your vcs to your blogging engine, all the way down to your rss feed
<canton7> heftig, sqlite for me
<aprescott> and again, what happens if you alter the file so git sees a new timestamp but the semantic content of the post hasn't changed?
<drbrain> aprescott: you have to tie the timestamps to something
<heftig> canton7: sure, that sounds good
<aprescott> drbrain: :((
<heftig> wanted to use a ORM to get some abstraction
<canton7> heftig, DataMapper's my personal preference, but a lot of it's down to taste
<aprescott> drbrain: if i stay with the approach of keeping everything in metadata, the timestamps are not human-friendly, and it means either just Dealing With That, or writing some manager of the metadata at the top of each file
<aprescott> which then starts to become an obstacle to the idea of "it's just files", i dunno
<drbrain> aprescott: be that an automatic system like git, or a manual system like hand-editing a flat-file or metadata entries in the file itself
<aprescott> right, you have to have that data somewhere
<drbrain> tying to git doesn't sound like a terrible solution, and it'll probably be easy for you to remember "don't make changes"
<aprescott> i just can't think of something that actually does represent the timestamps in terms of the semantic data of the blog post
io_syl has joined #ruby-lang
<drbrain> that is, unless you need to fix a typo or add an important update
<aprescott> drbrain: hm, but then i guess it doesn't matter about timestamps updating because of those changes.
<aprescott> unless feed readers mark an updated item as unread.
<aprescott> google reader is the only client i use, and it keeps a read item as read, even when it picks up a later updated-at time
<aprescott> gonna ponder this one some more maybe
andrewhl has joined #ruby-lang
fgomez has joined #ruby-lang
<dontbecold_> dumb question: with a socket, is there any way to specify the type of line endings?
ando_ has joined #ruby-lang
aprescott has quit [#ruby-lang]
<drbrain> dontbecold_: you're using puts? yes…
H2H has joined #ruby-lang
<drbrain> set $\
<dontbecold_> drbrain: yus, Socket#puts I believe
<dontbecold_> drbrain: thank you :)
macmartine has joined #ruby-lang
<drbrain> dontbecold_: at least, that's supposed to work
<dontbecold_> drbrain: I set $\ to "\r\n", and it didn't do anything
Synthpixel_ has joined #ruby-lang
<dontbecold_> drbrain: is there a documentation page for the global variable set?
<drbrain> dontbecold_: ah, it's for print, not puts
<drbrain> ruby -e '$\ = " world\n"; $stdout.print "hello"'
<dontbecold_> drbrain: yea, http://www.zenspider.com/Languages/Ruby/QuickRef.html#pre-defined-variables said print and IO.write
<dontbecold_> I'm not sure where half the documentation for the Socket class actually is, I have no idea where the #gets and #puts methods even come from
<drbrain> IO
fgomez has joined #ruby-lang
<dontbecold_> So it's simple inheritance?
<drbrain> yeah
<dontbecold_> wow now I feel stupid
<dontbecold_> so instead of using IO#puts, I could use IO#print instead?
<drbrain> if you set $\, yes, but that's across all uses of print
outoftime_ has joined #ruby-lang
<drbrain> I usually do output = []; output << "line1"; …; io.write output.join "\r\n"
<dontbecold_> IO#print abides to $\, which is nil, so if I keep it nil, I just need to write every message to the socket with "\r\n" on the end of it
<drbrain> yes
<dontbecold_> hmm, there are probably a billion ways of doing this
<drbrain> dontbecold_: usually, Array#join is better than String#<< since there are fewer bytes to shuffle around when reallocating an Array compared to a String
spuk has joined #ruby-lang
SkramX has joined #ruby-lang
<dontbecold_> drbrain: I'm usually only writing one line out to the socket, I can't think of a case where I need to write out more than one
<dontbecold_> drbrain: then again, i've only skim-read the RFC :(
<dontbecold_> drbrain: thanks for the tip, i'll keep it in mind
<drbrain> dontbecold_: then just write out the one line until the RFC says different :D
Brainix has joined #ruby-lang
Synthpixel has joined #ruby-lang
Radium has joined #ruby-lang
Banistergalaxy has joined #ruby-lang
tjadc has joined #ruby-lang
Banistertab has joined #ruby-lang
FiXato has joined #ruby-lang
andrewhl has joined #ruby-lang
charlenopires has joined #ruby-lang
io_syl has joined #ruby-lang
ando has joined #ruby-lang
<whitequark> just wrote this
<whitequark> (interface? ? :interface : :class)
<whitequark> buffalo buffalo buffalo ...
imperator has joined #ruby-lang
charlenopires has joined #ruby-lang
FiXato has joined #ruby-lang
netsmith2012 has joined #ruby-lang
<dontbecold_> whitequark: I think that just made my day
netsmith2012 has quit [#ruby-lang]
<erikh> hey folks!
fgomez has joined #ruby-lang
mistym has joined #ruby-lang
<rue> HI THERE
sandbags has joined #ruby-lang
netsmith2012 has joined #ruby-lang
netsmith2012 has quit [#ruby-lang]
futurechimp has joined #ruby-lang
<jmontross> hi there
<jmontross> erikh - erik herikas?
<erikh> no.
<jmontross> k.. didn't think so.. long shot.
<shevy> erik huerta?
<erikh> yeah, so /whois erikh if you really care
<erikh> :P
<dontbecold_> https://github.com/erikh, how's California? ;D
<erikh> warm
<dontbecold_> Lucky, GB is cold :(
<erikh> but your name is dontbecold_ !
<erikh> but yeah, it's pretty nice out.
<jmontross> hey - i'm down street in los gatos… it is nice today… 60s
ttilley has joined #ruby-lang
Banistergalaxy has joined #ruby-lang
Joeysomo has joined #ruby-lang
L0rdShrek has joined #ruby-lang
enebo has joined #ruby-lang
hahuang65 has joined #ruby-lang
igotnolegs has joined #ruby-lang
tom___ has joined #ruby-lang
<tom___> hi
<tom___> i have a question
<tom___> please look at this code:
<tom___> format.html { redirect_to '/shoutbox', notice: 'Shoutbox entry was successfully created.' }
<drbrain> we have an answer
andrewhl has joined #ruby-lang
<tom___> what does notice: mean ?
<tom___> shouldnt it be :notice => ?
<drbrain> it is new Hash syntax for ruby 1.9
<drbrain> it is equivalent to :notice =>, but IMO looks nicer
<tom___> ok, thanks for your help!