Topic for #ruby-lang is now Ruby 1.9.3p0: http://ruby-lang.org | Paste >3 Lines of Text on http://pastie.org
yfeldblum joined #ruby-lang
<mztriz> "./injekt.rb ../test \.rb$ .rb.old"
<mztriz> if I cd to my "test" dir I've got a few files that end in .rb
<injekt> mztriz: Regexp.new(match)
<injekt> inside 'grep'
<injekt> ~/code/slop[tomdoc]% blah . spec$ foo
<injekt> slop.gemspec
<mztriz> injekt, okay that works now :)
Banistergalaxy joined #ruby-lang
butchanton joined #ruby-lang
imperator left #ruby-lang
Pip joined #ruby-lang
Pip joined #ruby-lang
Spooner joined #ruby-lang
butchanton joined #ruby-lang
jmontross left #ruby-lang
matled joined #ruby-lang
j`ey joined #ruby-lang
dRbiG joined #ruby-lang
nofxx joined #ruby-lang
Enlik joined #ruby-lang
Enlik left #ruby-lang
ivorybishop joined #ruby-lang
outoftime joined #ruby-lang
thrcka joined #ruby-lang
slackstation joined #ruby-lang
nuclearsandwich joined #ruby-lang
<andrewhl> i've got an array of various data, and maybe 20% of the items are "19x19 Hn" were "n" is some number between 2-9. What I want to do is two-fold: I want to replace 19x19 wherever it occurs with just 19; secondly, I want to separate out the Hn into a separate array item: https://gist.github.com/1421135
<andrewhl> I'm using a slice to try to isolate "19x19", and gsub to replace it with something, but it's not working
kain_ joined #ruby-lang
QaDeS_ joined #ruby-lang
duckinator left #ruby-lang
igotnolegs joined #ruby-lang
<lianj> wth
WillMarshall joined #ruby-lang
AndChat- joined #ruby-lang
zedUNDginger joined #ruby-lang
mztriz left #ruby-lang
<andrewvos> jesus christ
<andrewvos> andrewhl: just use regular expressions
<andrewhl> that bad huh? lol
<zenspider> ugh
<zenspider> "parsing" html with regexps is a mistake
<dhoss> true
<andrewhl> ok, so one person says use regexp after invoking christ, and the other person uses scare quotes and calls regexp a mistake
<andrewhl> i'm a noob here, cut me some slack
flip_digits joined #ruby-lang
<andrewvos> parsing html with regular expressions is awesome
<andrewhl> i'll use satanic occult rituals of it'll get the job done
srbaker joined #ruby-lang
<wilkie> who doesn't like parsing context-free grammars with regular expressions?
<wilkie> well, it's only CFG if the HTML is sane, right?
<steveklabnik> lol
<zenspider> when was the last time you saw sane HTML?
<wilkie> I said IF not WHEN :D
<zenspider> true
<wilkie> fiiiiine XHTML
<steveklabnik> :D
<andrewhl> i didn't generate the HTML, I just want to parse it into something usable
<steveklabnik> nokogiri
<steveklabnik> then.
<zenspider> andrewhl: so if you want to parse it... PARSE it
<zenspider> slices and regexps != parsing
<andrewhl> also, actually, I want to learn ruby. Which I can scarcely claim to understand
<steveklabnik> eah
<andrewhl> using software seems to defeat the purpose
<zenspider> using software gets stuff done
<zenspider> which do you want?
<andrewhl> well, primarily, to learn, then get done
<andrewhl> call me crazy, but I'd like to do both
<steveklabnik> parsing is HARD.
<steveklabnik> learn how to do stuff with the things you're parsing.
<steveklabnik> and just parse it with nokogiri.
<wilkie> andrewhl: you want to learn parsing, too? then I'd be fine with you writing some LALR-esque thing and reading the dragon book, etc. :)
<zenspider> parsing doesn't have to be hard... but parsing html is retarded hard
<steveklabnik> zenspider: FINE PEDANT <3
<wilkie> haha
<andrewhl> I don't know what you just said wilkie
<steveklabnik> exactly.
<wilkie> andrewhl: if you don't want to learn or appreciate the sanity in your life, use an existing parser :)
<shevy> andrewhl try with StringScanner
<zenspider> using nokogiri is the right way to go
<zenspider> grab the nodes you want, munge your data as you need... it'll teach you plenty of ruby
<wilkie> I agree
<andrewhl> hmm
<andrewhl> ok then
<rue> zenspider: Parsing retarded (== average) HTML is hard
<zenspider> shut it you
<injekt> :)
<injekt> parse all the things!
<zenspider> even well formed/correct but clever html is a serious bitch
<zenspider> implied opens... implied closes... etc.
<steveklabnik> yeah
<steveklabnik> <p><b>this<i> is valid</b> so fucking use xhtml</i>
<zenspider> I think that's where I'm at, mentally
<injekt> looks good to me
<zenspider> hah
<rue> Tag files?
<zenspider> non-tag files... ruby files!
gregmoreno joined #ruby-lang
<rue> Indeed, but separate
<ReinH> zenspider: zomg hi!
<zedUNDginger> zenspider: (ignore him and let an awkward silence permeate)
edwardsharp joined #ruby-lang
<shevy> hmm
marcostoledo joined #ruby-lang
queequeg1 joined #ruby-lang
neoesque joined #ruby-lang
<ReinH> mission accomplished? :(
<ReinH> he hates me
<shevy> ReinH there can't only be friends.
<shevy> sometimes there must be enemies
<ReinH> Ryan is everyone's enemy
slaytanic joined #ruby-lang
<shevy> are you on ignore or something :D
WillMarshall joined #ruby-lang
<andrewhl> what's a good string method to see if a string contains a literal?
<andrewhl> i'm trying to use slice, but it's behaving strangely
<shevy> andrewhl "foo".include? 'o'
<andrewhl> ok thanks
mikeric joined #ruby-lang
heppy joined #ruby-lang
Oloryn_lt1 joined #ruby-lang
<shevy> if you need more control you could always use a // regex
dhruvasagar joined #ruby-lang
Bwild joined #ruby-lang
<shevy> :(
<shevy> I somehow broke my GCC
wyhaines joined #ruby-lang
FiXato joined #ruby-lang
<mksm> kewl
sinuc joined #ruby-lang
sinuc joined #ruby-lang
rkk joined #ruby-lang
tomzx joined #ruby-lang
twittard joined #ruby-lang
heppy_ joined #ruby-lang
nuclearsandwich joined #ruby-lang
Jade joined #ruby-lang
Jade joined #ruby-lang
srbaker joined #ruby-lang
brianpWins joined #ruby-lang
dr0id joined #ruby-lang
<andrewhl> how do you parse siblings using css in nokogiri?
<andrewhl> doc.css("div p") selects all ps that are children of divs... but how do I for example select the second table in a pair of sibling tables
<rue> Does CSS understand siblings?
<rue> andrewhl: You can use the Element/Node traversal once you have a set
<rue> It's got sibling-wise traversal.
<andrewhl> ok... uhm, what's the syntax?
<andrewhl> doc.node?
<rue> That #css returns a NodeSet, probably
<headius> zenspider: looking
Sailias joined #ruby-lang
<andrewhl> sorry, I'm confused. How do I select the sibling of something using nodes in nokogiri?
<andrewhl> I can't make heads or tails of the api
<andrewhl> api docs
<zedUNDginger> andrewhl: rue will help you
<rue> andrewhl: Look at the NodeSet methods
<dr0id> sibling selector ? div + p
<andrewhl> sorry, I only see XML::NodeSet in the nokogiri API, and I'm not parsing XML
<andrewhl> also, I have an html doc that basically contains two tables side by side, one of which I want, and the other I don't want
<andrewhl> maybe I can use xpath('//table')
twittard joined #ruby-lang
<andrewhl> no, that seems to get everything from //table
<theconartist> tables side by side?
<andrewhl> err, so to speak
<andrewhl> <table>...</table><table>...</table>
<theconartist> it has no other selectors?
<andrewhl> they have the same class
<andrewhl> annoyingly
<theconartist> im not sure if its [1] or [2] but that is what you want
<theconartist> the xpath is there to do what you want
<andrewhl> uhm, sorry, can you write that in context?
<andrewhl> [1] or [2] what?
<theconartist> you can use that with the xpath and nokogiri tree
<andrewhl> so... doc.xpath('//table[1]') ?
<theconartist> sure
<theconartist> its [2] for 2nd in xpath
<andrewhl> ok, [2] selects the second table... but if I want the first one, [1] selects both
<andrewhl> how can I narrow it down to the first one?
<theconartist> if 2 selects the second, 1 will select the first
<andrewhl> you'd think so, but it doesn't
<andrewhl> i just tested it
<andrewhl> ah, no, I think I'm wrong
<andrewhl> sorry
<andrewhl> the stupid things look almost identical
<andrewhl> ok thanks
<epitron> hmmm... i'm looking for an architectural pattern that makes sense for this IRC log parser i'm making
<epitron> i'm thinking, i want to do something like: log.each { |event| case event; when Messsage; ....; when Action; ... }
<epitron> then i'd have to have lots of subclasses though...
<zedUNDginger> epitron: do you trust the fidelity of a bose system
<zedUNDginger> do you consider them high quality
<epitron> zedUNDginger: not unless i heard it
<epitron> bose is pretty solid
<epitron> but every company can fuck up :)
phlipper joined #ruby-lang
<theconartist> epitron you could have a "router/handler" object and just .send(event, args) to that
<theconartist> make it look nice and pretty
jmcphers joined #ruby-lang
<epitron> hmmm
<epitron> so event would just be a symbol?
<theconartist> sure
nuclearsandwich joined #ruby-lang
<epitron> the thing is, the events have different amounts of args
<epitron> oh, i see what you're saying
<epitron> on_action, on_message, on_nickchange
<epitron> that's not a bad idea
<epitron> flip it inside out :)
<epitron> hmm...
<epitron> there is something nice about having it be an enumerator
<epitron> oh! we could combine these two methods
<epitron> the handler object would be the primary method of parsing the log
<epitron> and then there could be enumerable methods on the log object
<epitron> which automatically setup a handler for you
<epitron> eg:
<epitron> log.messages.select { |m| m =~ /http:\/\// }
Oloryn_lt11 joined #ruby-lang
<epitron> i wonder how people shove irc logs into sql databases
<steveklabnik> INSERT
<andrewhl> how can I get the contents of a tag in nokogiri?
<epitron> steveklabnik: oic
<andrewhl> e.g., <a href="">Contents</a>
<steveklabnik> andrewhl: doc.css('h3.r a.l').each do |link|
<steveklabnik> puts link.content
<steveklabnik> end
<andrewhl> ok thanks
<steveklabnik> http://nokogiri.org/ <-
<steveklabnik> :D
<epitron> i mean, how would you layout an SQL database that can store such disparate kinds of log data? messages, actions, mode changes, nick changes, topic changes, date changes...
<steveklabnik> ahh.
<epitron> maybe if i just stored everything as a string, and parsed it on the fly :)
<steveklabnik> or parse before inserting it
<epitron> type: nick change, regexp: /whatever/
<steveklabnik> you could just have a type column
<epitron> but some of those events are broken down into strange things
<epitron> quit has username, channel, quit message
<epitron> join has username, channel
<epitron> action has username, action
<epitron> mode has channel, mode, mode params
<epitron> ......and user
x0F__ joined #ruby-lang
<epitron> there needs to be a way of parsing out that data, since irc clients can log it differently
<theconartist> why not look at the IRC spec
<epitron> how will the irc spec help?
<theconartist> define the lines the same as they do
<epitron> that won't help with a database structure
<theconartist> well you don't have to structure the database down to the very last element
<theconartist> and if you do want to do that maybe go with something other than an rdbms
<epitron> hmmmmmmm
<epitron> to handle different log formats, i'm going to need to do it down to the last element
<epitron> oh! i should look at that perl irc stats script
<epitron> it handles like 500 log types
<theconartist> i dont know what you mean, you can re-encode it into a standard format before putting it into the db
<epitron> i think most people solve this problem with an array of hashes
<epitron> lots of little objects with different types and attributes
<theconartist> or make your own Event object instead of using a hash
sopheak joined #ruby-lang
<epitron> yeah... i could subclass Hash or something :)
<epitron> i could also just use a lot of structs
chronicole joined #ruby-lang
slackstation joined #ruby-lang
amerine joined #ruby-lang
ecin joined #ruby-lang
<epitron> http://pisg.sourceforge.net/ has a class that parses a line, and returns a hash with type and args...
ryanf joined #ruby-lang
<epitron> the code that returns the hash is called whenever its regexp matches
<epitron> that's nice and simple
looopy joined #ruby-lang
neoesque joined #ruby-lang
Ruthenium joined #ruby-lang
io_syl joined #ruby-lang
retro|cz joined #ruby-lang
imperator joined #ruby-lang
naz joined #ruby-lang
Banistergalaxy joined #ruby-lang
ecin_ joined #ruby-lang
ecin joined #ruby-lang
ecin_ joined #ruby-lang
<shevy> hmm are you guys using Readline a lot?
<shevy> for me it seems to have slowly replaced $stdin.gets ... but the tab completion micro-managing kinda annoys me
<shevy> perhaps my brain fits only into the stdin.gets world
igotnolegs joined #ruby-lang
<rue> Use readline (or ruby-rl or editline or coolline) when needed
kitallis joined #ruby-lang
<imperator> or rawline
<erikh> hello I am using the internet
<edwardsharp> hi
<edwardsharp> welcome to the internetz
<erikh> such a nice young man
<erikh> have a lollipop
<imperator> you're lucky, the intertubes were clogged earlier, but it's all ok now
<Banistergalaxy> Lick me like a lollipop
<Banistergalaxy> Lil wayne
<rue> Ew, why do you want him to do that?
<Banistergalaxy> Making me happy feeling
<Banistergalaxy> Andrewvos watch who's afraid of virginia woolf
<edwardsharp> swampy!
<epitron> does anyone know what the scope of regexp matches is? ($1, $2, etc..)
<epitron> eg: def special_matcher(string, regexp, &block); if string =~ regexp; yield; end; end
<epitron> special_matcher("hello", /(ello)/) { $1 }.should == "ello"
sgd joined #ruby-lang
<epitron> apparently the $1 gets clobbered. :\
<rue> Clobbered?
<epitron> it's nil
<epitron> the $1 isn't global, apparently
<epitron> it's got some kinda scope
<rue> No, it's not global
<rue> Each method's got its own scope, but
singpoly1a joined #ruby-lang
<rue> I think gsub &c. might use some trickery to propagate it
<Ruthenium> $1?
<Ruthenium> where you got that from?
<ryanf> it's actually local isn't it?
<ryanf> oops I didn't mean to say that
<ryanf> I typed it out and then was like "wait, I have no idea if that's true"
<rue> It's sort of local, yes
<ryanf> yeah, the sort of part is the problem
<rue> Ruthenium: $1… are the numbered match groups from most recent match. We get it from Perl
<ryanf> along with other good stuff like $` and $'
<andrewhl> how do I represent the unicode multiplication symbol U+00D7 in ruby?
<Ruthenium> I just remembered
<andrewhl> i'm trying to put it in a string for a comparison and it's giving me an error
<ryanf> andrewhl: "\u00d7"
<andrewhl> thank you
imperator left #ruby-lang
<Ruthenium> epitron: ef special_matcher(string, regexp, &block); if string =~ regexp; yield $~; end; end
<Ruthenium> then in block extract groups from matchdata
<andrewhl> sorry, follow up question: how would I represent 9x9 where x is \u00d7
<rue> Wow, the C implementation is so much awesome.
<epitron> Ruthenium: ugh, this really gums up my api :)
<ryanf> andrewhl: should be "9\u00d79", no?
<andrewhl> that'll work? Ok I'll try it
<Ruthenium> api shouldn't be based on globals anyway
<Ruthenium> you have to somehow pass the arguments
<ryanf> the \u is always followed by four hex digits
<andrewhl> ah, ok
<andrewhl> thanks
<ryanf> there is also \x which is just one byte
<ryanf> two hex digits
<rue> Ruthenium: String#(g)sub doesn't, which is what I assume epitron's trying to emulate
<andrewhl> cool!
<epitron> rue: exactly
<epitron> convenience!
<epitron> consistency!
<rue> rbx explicitly sets the last match, I'm not quite sure what happens in MRI…
<Ruthenium> I see now
kitallisii joined #ruby-lang
<epitron> i assumed they were globals because they start with a $, and gsub makes them available to blocks
<steveklabnik> the $1 is more of a holdover from Perl.
<ryanf> some of the $ vars are thread-local too
<steveklabnik> they might happen to be global because of that.
<epitron> they're definitely not global :)
<ryanf> they aren't global
<steveklabnik> sweeeeet.
<ryanf> I also really prefer them to the match object api, tbh
<epitron> ooo.. interesting
<epitron> eval("$~ = $match", block) # the trick here.
<epitron> yield $&
<epitron> preceded by: $match = $~
<epitron> so $~ sets the $1, $2, etc.
wmoxam joined #ruby-lang
wmoxam joined #ruby-lang
Weems joined #ruby-lang
Weems joined #ruby-lang
jxie joined #ruby-lang
<rue> $~ is the last matchdata
<rue> Interesting workaraund
Asher joined #ruby-lang
zmack joined #ruby-lang
<epitron> ugh. binding.eval is so crude
<rue> …Yeah
<epitron> binding[:name] should let you set locals or something
<epitron> i guess a lot of evil voodoo would result from that though
kith joined #ruby-lang
<steveklabnik> lol
dr0id joined #ruby-lang
huug joined #ruby-lang
<ryanf> yes, awesome evil voodoo
<ryanf> jeez, what kind of pry committer are you
<Asher> steveklabnik - have you encountered thacker's new book hard code?
zedUNDginger joined #ruby-lang
yxhuvud joined #ruby-lang
JohnBat26 joined #ruby-lang
<epitron> ryanf: i'm just thinking like matz :)
<epitron> *I* would love binding.evil_voodoo
<steveklabnik> Asher: no, i have not.
<Asher> i was just flipping through it… struck me as another infuriatingly stupid take on code as literature
<steveklabnik> oh yeah?
ecin joined #ruby-lang
<steveklabnik> one review on amazon
<steveklabnik> 5 stars
<steveklabnik> lol
<steveklabnik> from 2004
<Asher> heheh
<Asher> oh ok i guess it's not new
<Asher> friend just sent it to me
ecin joined #ruby-lang
ecin_ joined #ruby-lang
sulo joined #ruby-lang
mikeric joined #ruby-lang
<headius> zenspider: I like it, but I have two concerns
<headius> zenspider: 1. filename collisions...does "name" include a path to the test?
<headius> zenspider: 2. method name collisions; more than one test defined in the same file could easily use the same test method names
<headius> otherwise, the structure seems sound
Weems joined #ruby-lang
Weems joined #ruby-lang
sulo joined #ruby-lang
heppy joined #ruby-lang
burgestrand joined #ruby-lang
headius joined #ruby-lang
poga joined #ruby-lang
arooni-mobile joined #ruby-lang
Carnage\ joined #ruby-lang
nuclearsandwich joined #ruby-lang
SuperTaz_ joined #ruby-lang
<sopheak> hi, can anyone tell me how to install gem?
jxie_ joined #ruby-lang
<andrewhl> I've got a regex: [1-9]?[1-9][kd]\W, it finds basically 1-99d or k. I want to also be able to find, simply: -
<andrewhl> how can I look for all that OR -
Banistergalaxy joined #ruby-lang
<rue> andrewhl: Use the or-operator in the regexp?
<rue> |
<andrewhl> ah,ok, thanks
zcdny joined #ruby-lang
zennny joined #ruby-lang
<sopheak> andrewhl, i already have RubyGem installed
<sopheak> and now let say i want to install RedCloth
<sopheak> what should i do?
<zcdny> How to copy a directory to specifying directory in rake
<andrewhl> gem install 'RedCloth' should work
<sopheak> so no need to download RedCloth file?
<andrewhl> no quotes, rather
<rue> Though there's probably a more current gem available
<andrewhl> no
<andrewhl> just do it from your terminal prompt, if on a mac
<sopheak> i did this way once before, but i get error. so maybe because of my internet connection
<sopheak> i get Error: Could not find a valid gem 'RedCloth' (>=0) in any repository
<shevy> hmmmmmm
<shevy> can you obtain the redcloth .gem somehow
<sopheak> is it case sensitive?
<zcdny> Hi , there, how to copy a directory to target directory with rake.
<zcdny> maybe you should download the RedCloth.gem for installing ,,, to sopheak
krz joined #ruby-lang
<sopheak> zcdny, that's working by downloading way
burgestrand joined #ruby-lang
robotmay joined #ruby-lang
<Banistergalaxy> Sup burg
<shevy> dumdedum
<burgestrand> Mornin :)
<shevy> die!!!
<shevy> oh wait, sorry
<shevy> wrong idiom
<shevy> hi :)
<Banistergalaxy> Check out updated site and give your swedish design opinion
<shevy> smorrebred smorrebred ramtamtam
<shevy> oh
<shevy> Sm�rrebr�d
<Banistergalaxy> Shevy you need to sleep
<shevy> Schmierbrot
<Banistergalaxy> It's a strange hour in austria
<shevy> damn it... that's from denmark
<shevy> Banistergalaxy it's almost 9:00 !
solars joined #ruby-lang
<shevy> soon I will go jogging for half an hour
<Banistergalaxy> But you haven't slept
<shevy> slept till 1:00
<shevy> jogging, eating, then I will make a nap at 12:00
<Banistergalaxy> I was taking to you at 4am yoko
<burgestrand> Looks good, but the text on the navigation item that’s currently selected (i.e. ”Home”) would need another color but that’s nitpicking :)
<Banistergalaxy> Too
<shevy> Banistergalaxy yeah, fell asleep at around 18:00 or something like that
<burgestrand> Managed to fit the logos without either of them looking bigger than the other, that’s nice
<Banistergalaxy> Burg check out screen casts page too
<burgestrand> Sweet :)
<burgestrand> Missing the Fork-ribbon though!
tallship joined #ruby-lang
Banistergalaxy joined #ruby-lang
<burgestrand> Banistergalaxy: mind if I link the ”contributors to the website” piece in the footer to GitHub? There’s a bunch of them but ippa’s the only name there :)
<Banistergalaxy> Sure
<burgestrand> Banistergalaxy: (also must say Spooner did some nice work and actually used all the stuff put in place to run the website such as the liquid markup and fancy CSS thingies)
<Banistergalaxy> Yeah hes a hours boy
<Banistergalaxy> Good
<ryanf> hours
<burgestrand> good typoed to hours? nice work :p
workmad3 joined #ruby-lang
zmack joined #ruby-lang
<Asher> am i the only one who thinks the thread on profanity and pejoratives in ruby is… retarded and lame?
resetexistence joined #ruby-lang
<ryanf> lmao
<ryanf> wasn't that like a week ago? or is it still going?
<Asher> i just sorted through my ruby box
ecin joined #ruby-lang
Axsuul joined #ruby-lang
gnufied joined #ruby-lang
roadkith joined #ruby-lang
zedUNDginger joined #ruby-lang
zedUNDginger joined #ruby-lang
nuclearsandwich joined #ruby-lang
sandelius joined #ruby-lang
Banistergalaxy joined #ruby-lang
zerokarmaleft joined #ruby-lang
rpall joined #ruby-lang
havenn joined #ruby-lang
ecin joined #ruby-lang
thrcka joined #ruby-lang
timbleck joined #ruby-lang
hipe joined #ruby-lang
Mon-puchi joined #ruby-lang
jensn joined #ruby-lang
matti joined #ruby-lang
matti joined #ruby-lang
solars joined #ruby-lang
adambeynon joined #ruby-lang
ecin joined #ruby-lang
workmad3 joined #ruby-lang
dhruvasagar joined #ruby-lang
Tallboy joined #ruby-lang
<Tallboy> hi
Tallboy left #ruby-lang
zedUNDginger joined #ruby-lang
<dr0id> lo
Ruthenium joined #ruby-lang
burgestrand joined #ruby-lang
benanne joined #ruby-lang
sirfilip joined #ruby-lang
<sirfilip> morning
<muzone> morning!
<zedUNDginger> sirfilip: you're not here this isnt happening
<sirfilip> yup it is all part of the matrix
<sirfilip> take the green pill mate
jasox joined #ruby-lang
lenilson_dias joined #ruby-lang
WillMarshall joined #ruby-lang
thrcka joined #ruby-lang
WillMarshall joined #ruby-lang
saLOUt joined #ruby-lang
Guedes joined #ruby-lang
Guedes joined #ruby-lang
zedUNDginger joined #ruby-lang
<shevy> and the pink pill
<rue> Pretty much just take all you're offered
<j`ey> rue: is that your policy?
<rue> Yep
<j`ey> cool
zmack joined #ruby-lang
Jake232 joined #ruby-lang
diegoviola joined #ruby-lang
pcwormald joined #ruby-lang
Squarepy joined #ruby-lang
Squarepy joined #ruby-lang
molgrew joined #ruby-lang
beiter joined #ruby-lang
singpolyma joined #ruby-lang
sopheak joined #ruby-lang
wyhaines joined #ruby-lang
robotmay joined #ruby-lang
wyhaines_ joined #ruby-lang
jensn joined #ruby-lang
jasox joined #ruby-lang
wyhaine__ joined #ruby-lang
wyhain___ joined #ruby-lang
wyhain___ joined #ruby-lang
wyhai____ joined #ruby-lang
wyhaines_ joined #ruby-lang
RomD` joined #ruby-lang
wyhaines joined #ruby-lang
wyhaine__ joined #ruby-lang
wyhaine__ joined #ruby-lang
wyhain___ joined #ruby-lang
wyhai____ joined #ruby-lang
wyhaines_ joined #ruby-lang
wyha_____ joined #ruby-lang
wyh______ joined #ruby-lang
wyhaines joined #ruby-lang
judofyr joined #ruby-lang
wy_______ joined #ruby-lang
wyhaine__ joined #ruby-lang
Squarepy joined #ruby-lang
Squarepy joined #ruby-lang
marcostoledo joined #ruby-lang
yourstrly joined #ruby-lang
yourstrly left #ruby-lang
flip_digits joined #ruby-lang
sopheak joined #ruby-lang
<shevy> zedUNDginger what
<shevy> caller[0] !!!
<zedUNDginger> shevy: i mean the method name puppy
saLOUt joined #ruby-lang
zedUNDgi_ joined #ruby-lang
<shevy> __method__ !!!
<shevy> though I found something odd
<shevy> lemme try to find it ...
<shevy> def foo(i = Kernel.__method__)
<shevy> that did not work as I expected it to work :(
<shevy> so my second solution was to do this inside every method of the class:
<shevy> register_last_method_call(Kernel.__method__)
<shevy> and that was also way too annoying
JohnBat26 joined #ruby-lang
rufsketch1 joined #ruby-lang
<rufsketch1> how smart is Ruby about sorting arrays?
<judofyr> rufsketch1: depends on the elements in the Array
<rufsketch1> if an array is already sorted, does Ruby know that and take advantage of it to put an element in?
<judofyr> rufsketch1: nope. you could create a SortedArray though
<rufsketch1> Well, I have a bunch of "word" objects. That contain various variables describing the words.
<rufsketch1> Ah, I'll look into that
<rufsketch1> thank you
<judofyr> rufsketch1: ah, no, I meant: you could create your own class
<judofyr> (called SortedArray)
<rufsketch1> judofyr, ah. Yes. I'm already doing that
<judofyr> that would actually be very useful
<rufsketch1> I was just hoping there was something out there already
<judofyr> don't think so
<judofyr> rufsketch1: you plan on supporting every method on Array?
<rufsketch1> Yes. It would. Alright, I'll create this as general as possible then
kris joined #ruby-lang
<rufsketch1> judofyr, hmm, I guess I could start a seperate project for it.
<rufsketch1> Ideally though, I'd just post the code somewhere and have everyone else add the minutia
<molgrew> like the implementation?
<rufsketch1> molgrew, no, like all of the functions Array supports
<judofyr> rufsketch1: actually, you might want to checkout a RB-Tree
<judofyr> or maybe not
<judofyr> a sorted array works pretty similar though
kris left #ruby-lang
<molgrew> what happens if you find it is not ye sorted after checking for sortedness?
<judofyr> rufsketch1: will you allow duplicate entries?
<judofyr> rufsketch1: if not, you can use SortedSet
<bnagy> hrm
<molgrew> are you okay with doing the same things many times?
<judofyr> rufsketch1: require 'set'; a = SortedSet.new; a << 2; a << 1; a.each { |b| p b }
<bnagy> if you're going to have enough entries for it to actually matter, then why not use a DB of some kind?
<rufsketch1> judofyr, wait, is sorted set a thing?
kristal_ joined #ruby-lang
<bnagy> otherwise just sort / select when you need to
<rufsketch1> judofyr, ah, thank you.
<rufsketch1> bnagy, that was my initial idea. As I will be dealing with 500MB of data. So I figured I'd try it both ways as a good way to learn more about Ruby.
<rufsketch1> bnagy, can you link me to a guide on using ruby with Databases?
<judofyr> rufsketch1: it's set-oriented though, so it might or might not be the best solution
<rufsketch1> judofyr, the problem I'm solving is set oriented.
<rufsketch1> judofyr, I'm creating a program to beat a common creativity test
<judofyr> rufsketch1: well then SortedSet should do the job :)
<rufsketch1> the "remote associates test"
<rufsketch1> So I'm indexing 900 works of fiction for words. And taking all the words associated with those words. All I need is a count variable associated with each word to determine how often they appear
<bnagy> rufsketch1: if you want the easiest possible route then I would suggest OklahomaMixer and tokyocabinet
<rufsketch1> bnagy, I started Ruby two days ago, so if you could give me more info . . .?
<bnagy> google will provide
<judofyr> rufsketch1: OklahomaMixer has some performant sorted set I think
<bnagy> basically tokyocabinet is a pretty good choice for local file backed DBs but it's not a 'real' networked db like redis / postgres etc etc
<bnagy> but it's quick and easy and stuff
<bnagy> I think the btree DB might be useful, but I haven't really thought about it. I use it mainly as a fast KV store
<judofyr> rufsketch1: you can use the B+Tree as a sorted set
<rufsketch1> bnagy, yeah, I just can't find anything on oklahoma mixer
flip_digits joined #ruby-lang
<rufsketch1> thanks for all the help judofyr, really appreciate it.
<rufsketch1> bnagy, too
cyri_ joined #ruby-lang
scottschecter joined #ruby-lang
<bnagy> rufsketch1: if you use oklahomamixer here is a big tip
<bnagy> :rcnum (record caching) is 0 (disabled) by default
<bnagy> that KILLS performance
<bnagy> so crank it up to whatever your system RAM can take
Spooner joined #ruby-lang
mantono joined #ruby-lang
<rufsketch1> bnagy, I'll keep it in mind for performance heavy applications
sepp2k joined #ruby-lang
imperator joined #ruby-lang
<imperator> good morning
<bnagy> hail caesar!
kedare joined #ruby-lang
<imperator> love it when i post to ruby-talk-google and my post disappears
<roadkith> hmmm billig software rigged to ical would be kinda cool
<roadkith> billing
<imperator> bnagy, howdy; been a while i think
shevy joined #ruby-lang
<bnagy> imperator: yeah, too much travel
jasox joined #ruby-lang
<bnagy> but got a few weeks coding now... well 2.5 weeks I guess :S
krz joined #ruby-lang
singpolyma joined #ruby-lang
<imperator> did you ever end up creating a dbgeng wrapper?
<bnagy> yep
<bnagy> FFI ftw
<shevy> hmm
<imperator> wish i had a use for it; like to see how it's used in practice
<bnagy> all kinds of stuff
<bnagy> but mainly for security geeks I guess
<bnagy> you can use it as a poor (and slow) man's instrumentation framework
<bnagy> or just when you need to script some debugger stuff for lots of input files
<imperator> love to see a presentation on it
zedUNDginger joined #ruby-lang
Manhose joined #ruby-lang
<imperator> no gem yet, eh?
<imperator> downside of ffi is that it requires mingw still
<bnagy> yeah I am not good a dev
<bnagy> I don't know how to make gems properly :(
<bnagy> lots of the stuff in there won't work with win32api, from memory it was a limitation on callback arg vector lengths
<bnagy> but also, once I started getting familiar with ffi it's really nice to use
<imperator> yeah, it's capped at 9 or something
<imperator> ffi drives me batty
<imperator> the post that went missng was an ffi post actually
<bnagy> I'm sure I could make my ffi stuff more idiomatic, but I found that there is verrry little doc that's windows specific
<imperator> that is one advantage to it
<bnagy> so a lot of it was trial and error, followed by OH! I can do it THAT way (refector in 25 other places)
<judofyr> bnagy: maybe Gemify can help you? http://dojo.rubyforge.org/gemify/ :-)
<imperator> he's got his code kind of organized weirdly there
<imperator> buggery.rb at the toplevel, everything else under lib?
<imperator> easily cleaned up, though
<imperator> and no tests? *gasp*
<imperator> :-P
<bnagy> yeah I don't know how to write a test suite for something like this
<bnagy> I have tested it a LOT, but with grind testing
<bnagy> it does leak a tiny bit in some cases, but I think that's in dbgeng not in my code
rippa joined #ruby-lang
zedUNDginger joined #ruby-lang
mdel joined #ruby-lang
<bnagy> I occasionally try and work out what the current fashion is for gems, then it all gets Rakefile and tests and crap I don't care about and I lose the will to live
<judofyr> bnagy: just create a gemfile
<judofyr> bnagy: although I would probably replace those `git ls-tree`
yfeldblum joined #ruby-lang
<judofyr> bnagy: replace them with: Dir["**/*"] and Dir["bin/*"]
<judofyr> you don't really need s.test_files
<bnagy> ... ok I'll look at it tomorrow
<imperator> bnagy, if you add me to the project i can help you organize it :)
<bnagy> I know it shouldn't be that hard, but :/
<bnagy> imperator: ha! srsly?
<imperator> sure
<imperator> if you don't mind me moving stuff around a bit
<bnagy> ok all done, I think
tommyvyo_ joined #ruby-lang
<bnagy> but I srsly need to get going, I have cooking to do
<imperator> ok, cya, thanks
<bnagy> no, thank you :)
<imperator> was gonna ask you an ffi question, but later
<bnagy> go ahead, I'll either know or not, probably
<bnagy> I am definitely no expert though
<imperator> one sec
mark_locklear joined #ruby-lang
Natch| joined #ruby-lang
<bnagy> :/
<bnagy> looks right to me?
<bnagy> documentation fail maybe?
<imperator> yeah, i don't get it either
tommyvyo_ joined #ruby-lang
<imperator> well, it works on most platforms
<imperator> it's like it isn't picking up the terminating nulls, and it's all blobbed together
<imperator> or something
<bnagy> that's what I would start with yeah
<bnagy> get the first thing as a byte array and see if all the data is in there
<andrewvos> I've got some haml that looks like this: = bla_bla
<andrewvos> bla_bla outputs a html string
<andrewvos> returns I mean
<andrewvos> Haml seems to escape the string I output. How can I make it not do this?
<imperator> bnagy, how would i unravel it as a blob of bytes?
<imperator> use a :char FFI::MemoryPointer instead?
Manhose joined #ruby-lang
<andrewvos> steveklabnik: Thanks dude.
<steveklabnik> np
<bnagy> imperator: well actually that char* you're using should be fine
<bnagy> it's just in how you read it out
<bnagy> like when you puts it then the terminator is honoured
<bnagy> there are a ton of read_array_of... methods
<bnagy> which should work, maybe
<bnagy> sadly a lot of the stuff I have done is basically brute force coding, so I don't have an awesome understanding of what will work before I try it :)
Pip joined #ruby-lang
<bnagy> but yeah you're not reading it as :string, so it should just be a byte array len 257
<imperator> alright, i'll tinker some more
<imperator> i usually just get segfaults when i try the various read_array_of methods :(
<bnagy> yeah that's the best thing about ffi. segfault city.
<bnagy> ok srsly though, gotta cook :D
<bnagy> o/
<vereteran> how do i tell rb_scan_args that i want one or two arguments (second argument is optional)?
danishman joined #ruby-lang
<imperator> bnagy, ok, thanks, enjoy the cooking
<imperator> vereteran, rb_scan_args(argc, argv, "11", &var1, &var2);
<imperator> "11" => 1 mandatory, 1 optional
<vereteran> imperator, thank you
<vereteran> but what if i have more than 9 arguments?
<vereteran> how do i put 10?
<vereteran> just curious
<imperator> 10?
<imperator> oic
<judofyr> vereteran: you shouldn't have more than 9 arguments :)
<imperator> at that point, you should be using hash args
sepp2k joined #ruby-lang
<imperator> as a general rule, if i have more than 3 arguments to a constructor i go to hash args
<vereteran> just interested, i don't have such function. in ruby i can add even 20 args (thats the maximum my patience allowed to type aN = nil, :))
<imperator> i've never done it, not sure if "110" would work or not
wyhaines joined #ruby-lang
<vereteran> didn't work here. i'll consider thats just impossible than
<vereteran> thanks for help
io_syl joined #ruby-lang
io_syl joined #ruby-lang
<judofyr> vereteran: seems that Ruby supports at least more than 500 parameters :)
Aravindnaidu joined #ruby-lang
robbrit joined #ruby-lang
<vereteran> heh how did you find out? typed in / generate method with 500+ params? :)
<judofyr> generated
<judofyr> method(:foo).parameters.size # => 50000
<judofyr> wow
<steveklabnik> lol
dustin__ joined #ruby-lang
<judofyr> steveklabnik: what? all my methods take at least 14 parameters!
<steveklabnik> ... there's some sort of joke in there
<judofyr> steveklabnik: you clearly haven't seen my latest projects ;)
kitallis joined #ruby-lang
<judofyr> yes, a terrible, terrible joke
<judofyr> gah
<steveklabnik> :D
<judofyr> I'm bored
roadkith joined #ruby-lang
<steveklabnik> it happens.
<imperator> judofyr, write some code or something ;)
<judofyr> imperator: I'm working :P
<judofyr> so I'm writing lots of code
<judofyr> Perl
<imperator> you poor man
<judofyr> btw, steveklabnik & imperator: I need a name for a project!
<judofyr> it's a documentation tool
<judofyr> for some reason, I've called it "Mecca" for now
<judofyr> but it's a little bit offensive
<judofyr> so I want another one
<dr0id> judofyr: are you good with css3 ?
<judofyr> dr0id: what part of CSS3?
<dr0id> gradients, rounded corners, transform , transition, etc.
<judofyr> not really
<dr0id> stay bored then
<judofyr> :)
<dr0id> :P
Xzyx987X joined #ruby-lang
<judofyr> dr0id: what's up?
<dr0id> you could make some submissions to css-creations.com and get rid of your boredom :P
<imperator> judofyr, what are you documenting?
<judofyr> imperator: Camping
nuclearsandwich joined #ruby-lang
Aravindnaidu left #ruby-lang
<imperator> Camping the micro framework, or camping the outdoor activity?
<judofyr> imperator: micro framework :)
Aravindnaidu joined #ruby-lang
malev joined #ruby-lang
<ReinH> I prefer the latter
<perplex> judofyr: about method parameter size.. limit seems to be between 130700 and 130750 somewhere.
<ReinH> o_O
<ReinH> perplex: probably 2^17 or so
<perplex> class Foo; def method_missing(name, *rest); puts "Called #{name} with #{rest.size} parameters."; end; end;
<perplex> f = Foo.new
<perplex> pry(main)> f.send(:abc, *(1..130500))
<perplex> Called abc with 130500 parameters.
<perplex> => nil
<perplex> pry(main)> f.send(:abc, *(1..130750))
<perplex> SystemStackError: stack level too deep
<ReinH> word
<Aravindnaidu> which factors may could limit the size of arguments to a method?
<perplex> tried with 130740 and then I get segfault and stack trace
<ReinH> 2^17 - number current stack frames, perhaps
<ReinH> - some other fudge factors
<ReinH> why exactly is this a thing that you need to know? o_O
<imperator> judofyr, i vote for....scamper
<judofyr> ReinH: it's good to know the next time you need a method with ~130000 parameters
<ReinH> I mean, I guess
<ReinH> but why
<perplex> It came up on irc, that's why
Manhose_ joined #ruby-lang
Sailias joined #ruby-lang
<ReinH> k
slyphon joined #ruby-lang
dv310p3r joined #ruby-lang
JEG2 joined #ruby-lang
AlHafoudh joined #ruby-lang
<AlHafoudh> hi all
<AlHafoudh> is there something like #tap, but it actually returns the value?
<rippa> tap returns the value
<judofyr> AlHafoudh: ehm, just .foo?
<judofyr> AlHafoudh: example?
<AlHafoudh> i need to do something like chain1.tap { |x| yield(x) }.chain2 so the yield return value is passed to chain2 etc
<steveklabnik> uhh
<judofyr> AlHafoudh: yield(chain1).chain2 ?
<AlHafoudh> judofyr: hmm, yeah, thats it! :) but I would like to put the tap in the chain, not around the chain (just cosmetic)
<ReinH> ...
<ReinH> why?
<steveklabnik> ....
<steveklabnik> lolz
<ReinH> I know what a hammer is, I'd just really prefer it if you tell me how to drive in this nail with a screwdriver instead
<ReinH> for *cosmetic* reasons
<AlHafoudh> yes :)
<ReinH> no
<AlHafoudh> ok, i will do it that way, anyway thank you
<ReinH> def useless_tap; yield self; end
<uzimonkey> if RString doesn't have an iv_ptr, how is it that a String object can have instance variables?
RickHull joined #ruby-lang
outoftime joined #ruby-lang
enebo joined #ruby-lang
MistyM joined #ruby-lang
mztriz joined #ruby-lang
nofxx joined #ruby-lang
RomD` joined #ruby-lang
zedUNDginger joined #ruby-lang
andrewhl joined #ruby-lang
<andrewhl> how can I change a positive number to a negative number in ruby?
<uzimonkey> multiply by -1?
<andrewhl> brilliant
<uzimonkey> sometimes things are simpler than they seem :P
<andrewhl> indeed
<ddfreyne> was expecting a #negated method actually
<uzimonkey> erm.. or even simpler, use the unary - operator
<uzimonkey> -some_number
<andrewhl> ok
RickHull joined #ruby-lang
outoftime joined #ruby-lang
<andrewhl> another question: if I have some_function(arg), and want to use regex to check for a certain literal in that arg, assuming the arg is an array, what can I use?
<andrewhl> i tried 'scan' but that's only for strings apparently
<ReinH> ddfreyne: the unary - is a "negation" method.
<ReinH> number = 10; -number #=> -10
<andrewhl> maybe I should use arg.each do |item| item.scan() end?
<RickHull> ary.select { |i| i.match(/.../) }
<ReinH> andrewhl: what's in the array?
<ReinH> strings?
<andrewhl> just simple strings, reinh
<ReinH> grep
<ReinH> Array#grep
<andrewhl> okay thanks
anachronistic joined #ruby-lang
<ddfreyne> ReinH: yep
<ddfreyne> ReinH: ST has #negated though
<ddfreyne> but I agree that it's not necessary
rayners joined #ruby-lang
macmartine joined #ruby-lang
<andrewhl> so if I understand this correctly: if (rank.grep(/d/)) will only work if the items in the array contain "d", yeah?
<andrewhl> or for the items containing d
<ReinH> it will return the items that match /d/
<andrewhl> sweet
zedUNDginger joined #ruby-lang
chendo_ joined #ruby-lang
<steveklabnik> is there a way to set an accept header with mechanize?
wmoxam joined #ruby-lang
wmoxam joined #ruby-lang
kmeehl joined #ruby-lang
anachronistic left #ruby-lang
<steveklabnik> specifically, i want to set Accept:application/xml
petercooper joined #ruby-lang
zedUNDginger joined #ruby-lang
zedUNDginger joined #ruby-lang
ivorybishop joined #ruby-lang
rbrooker joined #ruby-lang
<rippa> >Baby
kitallis joined #ruby-lang
voker57 joined #ruby-lang
voker57 joined #ruby-lang
* rbrooker refilling vitamins C 'n N Gone away for now
workmad3 joined #ruby-lang
Silowyi joined #ruby-lang
Skif joined #ruby-lang
<uzimonkey> if RString doesn't have an iv_ptr, how is it that a String object can have instance variables?
AlHafoudh joined #ruby-lang
Squarepy_ joined #ruby-lang
workmad3 joined #ruby-lang
mssola joined #ruby-lang
workmad3 joined #ruby-lang
rufsketch1 joined #ruby-lang
<rufsketch1> Does Ruby have a do while construct?
Weems joined #ruby-lang
Weems joined #ruby-lang
<shevy> rufsketch1 just while, without do
<rufsketch1> I want to execute code at least once more after a condition comes out false
<shevy> but loop {} is cooler
<shevy> while bla do
<shevy> something_here
<rufsketch1> And I didn't want to have to manually reconstruct the loop to do that
<shevy> something_there
<shevy> end if game_over
RomD joined #ruby-lang
<rufsketch1> shevy, that will allow the loop to execute at least once regardless of whether or not the condition is false?
<shevy> I am not sure I understand your question
vesan_ joined #ruby-lang
* rbrooker is back.
<rufsketch1> shevy, let's say I want to look at an element j in an array. and I keep doing some function on j until it hits the spot I want, but I don't want the loop to terminate once it hits that spot, I want it to go once more, just in case the next spot works too or whatever
kitallis joined #ruby-lang
infid joined #ruby-lang
<rufsketch1> shevy, yeah, I came from there, it's not what I want
heppy joined #ruby-lang
wyhaines joined #ruby-lang
kain joined #ruby-lang
<shevy> sorry, I still have no real idea what you need. :) It seems you want to iterate through an array, and you want to stop when you hit a condition... but not really
<rufsketch1> shevy, that was just an example. Let me think of a clearer one.
<rufsketch1> Let's say I'm coding the rules some sensors for a vacuum cleaning robot should follow, but there are other vacuum cleaner robots around. The robot has two sensors, one to check if there's dirt where it's going, and one to check if there's dirt right under it.
<rufsketch1> actually bad example
<rufsketch1> let me think of something else
<shevy> ok but
<shevy> why can't you just use two variables here?
Oloryn_lt1 joined #ruby-lang
<shevy> if dirt_at_target and dirt_under
<shevy> clean_up
<rufsketch1> it's a bad example, thinking of one where you don't have as much freedom
<rufsketch1> without being inelegant
riffraff joined #ruby-lang
<lianj> oO
<rufsketch1> shevy, let's say you want to search through a sorted array
<shevy> .select
geoffw8_ joined #ruby-lang
<rufsketch1> so you start at the half way point
<rufsketch1> no, manually
<geoffw8_> Hey all
<shevy> .each
<geoffw8_> just came from #rails with a question!
<shevy> actually I never started halfway from any array, I think
<geoffw8_> does anybody have a suggestion on the best way to work out the majority color of a photo?
<rufsketch1> then if your variable is greater than the variable at the half way point
zmack joined #ruby-lang
<rufsketch1> you move halfway between that and the end
<rufsketch1> or whatever as appropriate
rbrooker left #ruby-lang
<Mon_Ouie> shevy: Would you read all the words from the dictionary until you find the one you're searching for?
<shevy> YES
<lianj> :>
ecin joined #ruby-lang
<rufsketch1> shevy, so you keep track of where you were last
<shevy> .step
<rufsketch1> err, you keep track of the least lowest and least highest elements you were at last
<rufsketch1> and keep averaging them to find where you should go next
<lianj> man, just code it how you want and show it then
<shevy> that sounds like an algorithm from a drunk man
<rufsketch1> and you set the loop's terminating condition to be whenever you are looking at the same thing you were looking at last time
<shevy> he walks to the lowest point, then to the highest, then averages it, then repeats
<rufsketch1> because that means you've narrowed it down to one element
<rufsketch1> and you haven't found it
<rufsketch1> but, this would fail if you only have two elements
<shevy> lol
<rufsketch1> because the algorithm would *start* with you looking at the 0th element
<petercooper> CS grads.. remind me.. what's the name of the technique of picking the place to start a search based on the supposed distribution of the items? e.g. to look up "man" in the dictionary, I'd start in the middle since "m" is in the middle of the alphabet.
<rufsketch1> so you have to execute it at least once
<rufsketch1> petercooper, well, for sorting it's bucket
<rufsketch1> shevy, the algorithm is efficient
<rufsketch1> no drunkenness necessary
<shevy> ok let's get this forward somehow
<shevy> is not possible in ruby
kain_ joined #ruby-lang
ecin joined #ruby-lang
<Mon_Ouie> petercooper: binary search
<rufsketch1> shevy, it is, I just linked you to it
<petercooper> That's not based on the distribution of the items, though.
<petercooper> You always start in the middle there.
<shevy> ok
<shevy> is possible in ruby
io_syl joined #ruby-lang
io_syl joined #ruby-lang
butchanton joined #ruby-lang
<rufsketch1> petercooper, interpolated search, or dictionary search
<petercooper> Ah, that's it! Interpolated search. Thanks :-)
<rufsketch1> np
m0wfo joined #ruby-lang
<imperator> bnagy, first commit pushed :)
Weems joined #ruby-lang
Weems joined #ruby-lang
Indian joined #ruby-lang
infid joined #ruby-lang
JoelMcCracken joined #ruby-lang
<necromancer> hey so when using Dir.pwd i get the absolute path
geoffwright joined #ruby-lang
<necromancer> any way to just get the last folder?
<necromancer> or am i gonna have to .split() it with "/"?
<injekt> File.basename
<injekt> File.basename(Dir.pwd)
<necromancer> nice
<necromancer> thanks injekt
dejongge joined #ruby-lang
chendo_ joined #ruby-lang
riffraff joined #ruby-lang
thone_ joined #ruby-lang
<imperator> confused by 1.9 hashes
<imperator> h = {}; h[a: 2]
<imperator> h => {} - what?
<uzimonkey> imperator: that's not how it works
<imperator> how does it work?
<uzimonkey> h[a: 2] creates an implicit hash argument to Hash#[]
<uzimonkey> that's like calling h[{:a => 2}], and not assingin anything to it
<uzimonkey> you want h[:a] = 2
JEG2 joined #ruby-lang
heppy joined #ruby-lang
darkf joined #ruby-lang
Jake232 joined #ruby-lang
<rufsketch1> If I want to make a set of objects
<rufsketch1> how do I define by what standard the elements are identical?
zedUNDginger joined #ruby-lang
<injekt> rufsketch1: check out the docs for Set, and Object #hash and #eql?
<injekt> The equality of each couple of elements is determined according to Object#eql? and Object#hash, since Set uses Hash as storage.
<rufsketch1> injekt, thank you
heppy_ joined #ruby-lang
zedUNDginger joined #ruby-lang
slackstation joined #ruby-lang
<rufsketch1> injekt, I imagined it would determine equality if <=> returned zero
edwardsharp joined #ruby-lang
<injekt> rufsketch1: if you want it for sorting, sure
<injekt> Set is nice if you want unique elements and can test equality
<injekt> if you just want to sort, use <=>
<rufsketch1> injekt, how can I use it for sorting. I defined a sorted set, and have my <=> method set up, but when I insert two elements with value 'b' I get two copies of them
<rufsketch1> err, that is, the element gets added instead of replaced
<injekt> right, <=> is for sorting, you're not sorting, you're checking for equality on insertion
<rufsketch1> so I should create an eql method, and have it return the variable I want to use for checking equality?
<sirfilip> night
sirfilip left #ruby-lang
MrPunkin joined #ruby-lang
<rufsketch1> injekt, ah, I'll do the hash thing then. Though I can't figure out why this way doesn't work
<MrPunkin> is there any way to rescue a Floating point exception thrown from a C extension / gem within my ruby code, or will it just always kill the app before the rescue even gets triggered inside ruby?
<injekt> rufsketch1: sorry kinda in a meeting I can't open a browser right now
<rufsketch1> injekt, well, basically I wrote an if else statement that checked if the two string values I'm concerned about in the object are equal, and returns true or false accordingly
<rufsketch1> I also put a puts statement in the eql? method to see if it was getting called
<rufsketch1> but it looks like it's not even getting called
<injekt> rufsketch1: are you using a set?
<rufsketch1> injekt, sortedset
<injekt> eql should be getting called, I haven't seen your example but can you simplify it? just define an eql?(other) and print to ensure it's being called?
<rufsketch1> injekt, yeah, it's not getting called
<rufsketch1> injekt, although, I am using the .add method. And you are using .new
<rufsketch1> so maybe that is the issue
<injekt> rufsketch1: and you defined hash too right?
<injekt> rufsketch1: no, add is the same as <<
<injekt> rufsketch1: eql? wont be called unless the objects respond to hash
<rufsketch1> what does hash do?
<injekt> Generates a Fixnum hash value for this object. This function must have the property that a.eql?(b) implies a.hash == b.hash. The hash value is used by class Hash. Any hash value that exceeds the capacity of a Fixnum will be truncated before being used.
<injekt> :)
<rufsketch1> I'm still not seeing why this is necessary
<rufsketch1> but, okay
SteveG joined #ruby-lang
SteveG joined #ruby-lang
<rufsketch1> injekt, alright, it works. Thanks injekt
<injekt> rufsketch1: sure np
<MrPunkin> any way to rescue SIGFPE in ruby code?
<MrPunkin> rather than having it actually kill my app?
<injekt> MrPunkin: trap('SIGFPE') { #... }
<injekt> maybe?
mrsolo joined #ruby-lang
<injekt> MrPunkin: usually if an app is throwing SIGFPE something is very wrong
<injekt> so you probably shouldn't ignore/rescue it
<MrPunkin> injekt: Right. So I use this Gem called "Fraction" with rails that is a C extension to generate assumed fractions from floats / integers (0.3333334 to 1/3)
<MrPunkin> but if you use too big of a number it throws a core system level SIGFPE
Skif joined #ruby-lang
<MrPunkin> its code outside my control, but I can rescue my helper method to display the fractions to default to the crappy big number if I can catch it
<injekt> MrPunkin: so is it a bug in this extension?
<MrPunkin> Yes
<MrPunkin> I would assume
<injekt> is the library being maintained?
<MrPunkin> Yeah, I'll send the guy a note about it, but need it fixed now, it's on a production app that we use it
<uzimonkey> deosn't Ruby 1.9.x have Rational? doesn't that do the same thing?
<MrPunkin> yes, I'm on 1.8.7
<MrPunkin> still
<uzimonkey> ah, stuck in the dark ages..
<MrPunkin> yes
<uzimonkey> fix the bug in the library yourself? You could trap it yourself but that's sketchy at best
<rue> 1.8.7 has Rational too…
<MrPunkin> rue: Yes, but it doesn't do the assumed generalization to fractions
<uzimonkey> I was going to check, but I don't even have 1.8.7 anymore :P
<MrPunkin> so it makes ridiculously precise rationals
<MrPunkin> the rationalize method that 1.9 uses isn't in 1.8.7
<MrPunkin> that does all the fun rounding, etc.
ttilley joined #ruby-lang
<MrPunkin> uzimonkey: What is sketchy about trapping it myself in this one method? What do I risk?
<uzimonkey> well, probably not with SIGFPE
<MrPunkin> Seems the only risk is displaying the original number, not the converted to fraction version, for anything that causes a SIGFPE
<MrPunkin> in this one method
<uzimonkey> I remember I had this one program that, instead of fixing bugs the developers thought it would be a great idea to trap segfaults
<uzimonkey> that was.. a bad idea, but I guess SIGFPE would't be bad, how often does that come up?
<injekt> not a lot because it means something stupid is happening
<injekt> :D
<MrPunkin> uzimonkey: Just came up for the first time today, out of weeks of production use.
<MrPunkin> uzimonkey: some users' camera exif returned 630109000000.0 as the aperture, trying to convert to a fraction
<uzimonkey> you could sanitize the data first
zedUNDginger joined #ruby-lang
<MrPunkin> so just check for large numbers?
<MrPunkin> that's what I was starting out trying to do, but can't find a clean break for what is "too big"
lsegal joined #ruby-lang
<MrPunkin> seems 1000000000.0 works fine, but 3000000000 tosses the SIGFPE
<uzimonkey> check for something that wouldn't be an aperture number, I don't know anything about photography so I don't know what would be right
<uzimonkey> but just check for anything that would oterhwise break the lbirary
poga joined #ruby-lang
ecin_ joined #ruby-lang
<MrPunkin> uzimonkey: The problem is that we use this for more than just aperture, so it needs to work for a lot of numbers. So I guess I just check for huge numbers
<slackstation> How can I troubleshoot an issue with gems not loading for Sinatra? I don't think it's Sinatra, I think it's RVM, using zsh and my environment.
<MrPunkin> slackstation: how are you trying to load the gems? Are you requiring 'rubygems' or using bundler or anything?
<slackstation> I'm using bundler
<MrPunkin> so what code are you using to load? I use sinatra find with bunler
<MrPunkin> bundler
<slackstation> MrPunkin: Let me get the output...
dustin__ joined #ruby-lang
<slackstation> I can verify that bundler has loaded and installed ActiveRecord and I'm using Padrino purely with generators so there's no code I'm adding to the mix.
<MrPunkin> can you show boot.rb?
sepp2k joined #ruby-lang
<MrPunkin> slackstation: I'm not familiar with Padrino… does it load AR for you, or is that in your Gemfile?
<slackstation> MrPunkin: AR is in my Gemfile
Adam_R_29 joined #ruby-lang
hagabaka joined #ruby-lang
rippa joined #ruby-lang
epitron joined #ruby-lang
epitron joined #ruby-lang
<rufsketch1> Is there any way to interact with an object in a set?
<rufsketch1> Change on of its variables, for instance
<rufsketch1> without iterating through the set, I mean
<RickHull> yes, get a reference to that object
<rufsketch1> how?
<RickHull> i'm more familiar with arrays, is that sufficient?
<rufsketch1> no
<rufsketch1> :(
<RickHull> Sets have []
<RickHull> oh, hm, maybe just the class method
livinded joined #ruby-lang
<Mon_Ouie> set.each
<Mon_Ouie> They are enumerable
<rippa> [22:45:28] <rufsketch1> without iterating through the set, I mean
<rufsketch1> yeah
<RickHull> maintain a reference before set insertion
<RickHull> e.g. foo = MyObject.new; set.add(foo)
<rufsketch1> basically, the add function always checks to see if a the set already includes the element, so I wish the add function would return a reference to the element if it is included, so I could update that objects counting variable
ivorybishop joined #ruby-lang
<rufsketch1> RickHull, well, the issue is that I don't know which references I should and shouldn't continue to maintain. Because sets don't allow multiple instances of the same object
<rippa> set.add(foo) ? <modify foo here> : nil
<rufsketch1> rippa, what does that do?
<RickHull> except foo is different from the object in the set
saLOUt joined #ruby-lang
<Mon_Ouie> I don't think you can do that without getting the underlying hash
<Mon_Ouie> You can just use a hash yourself though
<RickHull> er, is it?
<rufsketch1> RickHull, if it is different, it doesn't get added
benanne joined #ruby-lang
<rufsketch1> RickHull, err, does get added
<rufsketch1> RickHull, well, depending on the definition of different
Adam_R_29 joined #ruby-lang
<rufsketch1> RickHull, if the set class deems it an equivalent object, it doesn't add. even if strictly speaking the object is distinct
<rue> rufsketch1: It's not really a set if multiple values are OK
<rufsketch1> yes
<rue> {obj => count} is probably best
<Adam_R_29> does anyone know if there is a room for active admin?
<Spooner> I have a bit of a problem with nanoc. Generally got everything working fine, but I want to #render a markdown file with a partial layout then #layout with 'default' layout. I can't work out how on earth to to that (I can do that sort of thing fine from haml, but not in markdown files accessed "directly").
<rue> A multiset would work, but…
<RickHull> Set does not use object_id for detecting sameness
phlipper joined #ruby-lang
<rufsketch1> rue, could you be more detailed. I'm new to Ruby
<RickHull> so it seems that your in-set foo and outer foo could change states independently
<RickHull> thus rippa's suggestion would not work, if you want to modify the in-set state
ChloeD joined #ruby-lang
cantonic joined #ruby-lang
<rufsketch1> RickHull, no, I want the in-set foo to be the only one that keeps existing. But have it change a variable each time an identical element tries to get added.
ubuntunoob joined #ruby-lang
ubuntunoob left #ruby-lang
<rue> rufsketch1: Maintain a Hash with the object as key, and the count as value
<RickHull> also ,using a set for mutating objects seems like a bad idea
<rue> The set datastructure is just unique unordered values
<rufsketch1> RickHull, well, for my purposes, it would be a wonderful idea.
<rufsketch1> rue, I'm using SortedSet
<rue> I'm sure you are, but how's that related to what the best solution is? ;)
<rufsketch1> rue, in the extent to which it minimizes the amount of work I have to do.
<RickHull> how's that workin out for ya? ;)
<rufsketch1> RickHull, still way below the work threshold of using an array
<RickHull> i like rue's hash suggestion
<rufsketch1> I don't quite understand it. I don't have any experience with Hash
<RickHull> your idea, as i understand, is the object has an internal counter
<RickHull> alternatively, you can track thte counter outside the object
<RickHull> hsh = { obj1 => count1, obj2 => count2 }; hsh[obj1] += 1
zmack joined #ruby-lang
<RickHull> you are facing difficulties using a Set, because they aren't designed for random access so you can mutate the contents
<rue> (With Hash.new 0, perhaps)
headius joined #ruby-lang
<rippa> Set is only a wrapper around Hash anyway
<rufsketch1> RickHull, rue, Alright, thanks I'll try using hashes
<Mon_Ouie> If you mutate an element that is in a set, it isn't equal to the value it had before, and its hash would change, and you'd need a rehash (i.e. rebuilding the set)
nuclearsandwich joined #ruby-lang
<rufsketch1> RickHull, rue, scratch that. Hash ends up being the same amount of work as an array. The include method doesn't give me an index, and there's no method to keep it sorted
<rue> The object *is* the index…
<rue> You can iterate keys sorted, but meh.
<rufsketch1> rue, okay, so then how do I find the index?
amerine joined #ruby-lang
<RickHull> let's revisit your concrete scenario
arooni-mobile joined #ruby-lang
<RickHull> you've got an object outside your counter structure
<RickHull> and you want to update your counter structure
<rufsketch1> rue, basically, I'm trying to build a huge list of words, and those words have a list of words with which they are associated. I need to keep track of how many times a word is associated with its parent word.
<RickHull> ?
<rufsketch1> it's huge, so I need to keep the list sorted so I can search quickly
<rufsketch1> to see if a word is already contained
ubuntunoob joined #ruby-lang
<ReinH> are there any #ruby ops in here?
<steveklabnik> sounds like you need something more than a hash.
<ubuntunoob> im having a panic attack.
<rue> Fucking #ruby.
<ubuntunoob> pleaes help.
<rufsketch1> bleh, alright I'll use arrays
<ubuntunoob> yea fuckin ruby doesnt work :S
<rufsketch1> deep breaths ubuntunoob
<RickHull> no, hash handles the searching quickly part
<rue> rufsketch1: Something more == objects
RomD joined #ruby-lang
<rufsketch1> rue, I'm already using objects
<injekt> ubuntunoob: you need to be a little more specific than that
heppy joined #ruby-lang
<bnagy> rufsketch1: what does 'associated' mean
<rufsketch1> each word is an object
ubuntunoob left #ruby-lang
<injekt> ...
<steveklabnik> lol
<injekt> nevermind
<rufsketch1> bnagy, it means that the word often appears in context next to the word in question
<bnagy> before or after?
<rufsketch1> both
<rufsketch1> either
<bnagy> or either
<ReinH> I'll take that as a no
<samuelkadolph> I was hoping zenspider would be around the ban ubuntunoob but he wasn't
<rufsketch1> I'm indexing 900 works of fiction
<rufsketch1> and counting associations
<bnagy> tbh I would give every word a db index and then keep a hash of index bigraphs
<bnagy> it's a very naive approach but the data set isn't actually that big
ilyam joined #ruby-lang
<bnagy> and it should all pan out on one runthrough
<rufsketch1> what sorting algorithm does ruby use for array.sort?
<bnagy> I don't see why you need to sort anything, ever, for the problem you're talking about
<RickHull> rufsketch1: a hash will immediately tell you if a word is already being tracked
<RickHull> assuming your word is a hash key
<RickHull> er, assuming you are using words as your hash key
<rufsketch1> RickHull, and then will it tell me where that word is located so I can change its count variable?
<RickHull> yes
<bnagy> 'I am a monkey' would end up in the db as 12=>1 23=>1 34=>1
<bnagy> KV stores will actually let you pull out partial keys efficiently
<rufsketch1> KV stores?
<bnagy> keyvalue
<rufsketch1> oh
<rufsketch1> alright, I guess I'll read up on hashes then
<RickHull> let's start with a simpler problem
<RickHull> counting words in a corpus
<RickHull> str = "I like the set of all things like myself"
<RickHull> hsh = Hash.new 0 # values default to 0
<RickHull> str.each_word { |w| hsh[w] += 1 } # does each_word even exist? who cares?
zedUNDginger joined #ruby-lang
<RickHull> hsh['like'] #=> 2
<rufsketch1> what's this |w| business?
<bougyman> it's what each_word is bound to in the block
<rufsketch1> ah
<RickHull> ary = [1,2,3]; ary.each { |i| puts i }; # 1, 2, 3
<bnagy> "I like the set of all things like myself".split(' ').each_with_object(Hash.new(0)) {|w,h| h[w]+=1}
<injekt> 1.9 only^
<bnagy> well unlike each_word with is imaginary ruby only
Manhose joined #ruby-lang
<RickHull> details shmetails...
<injekt> lol
<RickHull> the hash takes care of accessing the right slot for you
syphar joined #ruby-lang
<RickHull> no need to sort
<bnagy> +1 to that
<ReinH> twss
<bnagy> you don't need to sort for what you're explaining
<rufsketch1> is each_word pseudo code?
Codif joined #ruby-lang
<RickHull> yes
<RickHull> sorry about that
<RickHull> see bnagy's example for something you can actually execute
<RickHull> (on ruby 1.9 -- not 1.8, apparently)
<rufsketch1> .each_with_object is something I will have to read about
apeiros_ joined #ruby-lang
<bnagy> actually it's mainly good for showing off and one-liner competitions
<ReinH> it does what it sounds like
<bnagy> it's much more readable just creating an object
edwardsharp joined #ruby-lang
<rufsketch1> I get undefined for that fancy method
<rufsketch1> or
<rufsketch1> hang
<ReinH> wrong ruby
<injekt> rufsketch1: it's in 1.9 only
<rufsketch1> how do I check my version?
<injekt> ruby -v
<rufsketch1> ah, yes, 1.8.7
<injekt> 1.8.7
<injekt> :)
gregmoreno joined #ruby-lang
<bnagy> h=Hash.new(0);"I like the set of all things like myself".scan(/\w+/).each {|w| h[w]+=1}
Codif joined #ruby-lang
<bnagy> I don't endorse the scan approach tbh, I've been drinking
<RickHull> bnagy: uk?
<bnagy> no, rum
<RickHull> ha
Ater joined #ruby-lang
<injekt> you like in rum?
<injekt> live-
<RickHull> i mean, where is it happy hour?
<injekt> dammit
<bnagy> in kathmandu
<bnagy> well... it's a little after 1am, but that's happy enough in my book
<RickHull> oh shit, i remember asking you about that
<andrewhl> i'm trying to user grep to search an array using regex, but it doesn't return anything
<RickHull> red cross something or other?
<bnagy> rufsketch1: do you need to distinguish between pre and postpositions for your 'associated'?
<rufsketch1> bnagy, no
<andrewhl> myarray.grep(/"(...+)"/) for example, to find everything between ""s, returns nothing
<injekt> andrewhl: literally ... ?
<bnagy> ok so maybe what I would think about is giving all the words an index, right, so 'monkey' is now 125
<andrewhl> yeah literally. But if that's incorrect, even literals return nothing
<RickHull> 125 is a nonce, here?
<andrewhl> like I've tried all number of regex patterns, nothing returns
<bnagy> and then keeping a hash of word -> hash{ nearword->count }
<injekt> andrewhl: grep is for searching, looks like you're trying to extract
<andrewhl> yeah
<andrewhl> how do I extract?
<injekt> then you dont want grep
<injekt> you want map
<andrewhl> ok...
<bnagy> RickHull: just a db index, to save space, although it's optional
Codif joined #ruby-lang
<injekt> andrewhl: you want to replace everything in quotes with what's in the quotes?
<injekt> wait.. i can't speak today
<injekt> andrewhl: so '"foo"' becomes 'foo'?
<andrewhl> i have a hrefs, and I want to extract the urls
<bnagy> so for monkey you have my=>12 which would be 'my monkey' or 'monkey my'
<injekt> uh
<injekt> then parse them
<injekt> with a html parser
<andrewhl> from an array?
<injekt> sure
<injekt> they're merely strings
<andrewhl> i'm already using nokogiri to get it down to <a href="...">blah</a>
<injekt> then oO
<injekt> use nokogiri to extract the text
<andrewhl> but I don't know how to get JUST the url
<bnagy> so a hash of hashes... I think that would probably let you get whatever data you want pretty fast
<injekt> link[:href]
<injekt> boom
<andrewhl> oh
<andrewhl> interesting
<RickHull> headshot!
<andrewhl> zing!
<bnagy> imho you should differentiate between my monkey and monkey my though
<injekt> >> Nokogiri.HTML('<a href="foo">stuff</a>').at('a')[:href]
<injekt> => "foo
<injekt> "
yorickpeterse joined #ruby-lang
<andrewhl> I will try this madness you speak of
<injekt> word
<bnagy> then you can just step through each word and do update the previous word with association with me, update me with association with the previous word
<bnagy> so it's vaguely O(n) I think to process
<andrewhl> so wait, how would I convert this: doc.css('tr > td[1] > a').each do |stuff|
<andrewhl> or use [:href] in the context o fhtat
<andrewhl> of that*
<ReinH> Ruby is OO. Don't be afraid to create new objects that have the behavior you want.
<injekt> andrewhl: links = doc.css('.. a').map { |link| link[:href] }
<injekt> links is now an array of... links
<andrewhl> brilliant
<injekt> do you understand what map does?
<andrewhl> very vaguely. It iterates through an array apply a method to each item?
<andrewhl> applying*
<rippa> and stores results
<andrewhl> ok
<injekt> it yields each item to the block where you can do what you'd like with it
<injekt> creating a new array
<andrewhl> seems pretty magical
<injekt> wait till you see reduce!
<rippa> yay, inject abuse
<RickHull> ReinH: it's a bit magical for a beginner, but i like it :)
<erikh> objects like BenSTRING
<RickHull> ReinH: really, i was trying to show simple hash mechanics, which your solution tends to obscure :)
<bnagy> yeah apart from being longer, harder to read, and using reduce it's the bees knees
<rue> /me abuses injekt
<injekt> hay
<RickHull> thinking in terms of map/reduce rather than mechanically shuffling data around can be very helpful
lenilson_dias joined #ruby-lang
<RickHull> declarative rather than imperative, i suppose
ivorybishop joined #ruby-lang
<bnagy> I love map
<bnagy> I would totally do #map
<bnagy> #inject, meh, not so hot. Little scary, you know? Probably a cutter.
<injekt> heh
<injekt> injekt isn't scary, people just sometimes to stupid shit with it
<injekt> fuck
<injekt> inject*
<bnagy> srsly? illeism?
Jake232 joined #ruby-lang
<rue> MINSWANEMBEEIAN
robotmay joined #ruby-lang
<RickHull> inkjets are scary. who the hell wants the most expensive liquid in the world being shot all over the place
enebo joined #ruby-lang
<ReinH> bnagy: reduce is awesome
<ReinH> RickHull: functional rather than imperative
<RickHull> sure. i think what's nice about the functional approach is that it is declarative
<ReinH> sort of
<rue> Declarative is declarative
<RickHull> declarative declaration is declaritive
jasox joined #ruby-lang
<injekt> RickHull: I have been told my liquid is expensive
Codif joined #ruby-lang
empity joined #ruby-lang
troutwine joined #ruby-lang
RickHull1 joined #ruby-lang
resetexistence joined #ruby-lang
Pip joined #ruby-lang
mark_locklear joined #ruby-lang
postmodern joined #ruby-lang
brianpWins joined #ruby-lang
<soahccc> Does somebody have an idea why size on a Net::SFTP::Operations::Download::Entry is nil?
mikeric joined #ruby-lang
_inc joined #ruby-lang
Oloryn_lt1 joined #ruby-lang
grough joined #ruby-lang
workmad3 joined #ruby-lang
robbrit left #ruby-lang
grough left #ruby-lang
phlipper joined #ruby-lang
skyjumper left #ruby-lang
Manhose joined #ruby-lang
thegeekinside joined #ruby-lang
lsegal joined #ruby-lang
Weems joined #ruby-lang
Weems joined #ruby-lang
nofxx joined #ruby-lang
href joined #ruby-lang
Kivi joined #ruby-lang
lenilson_dias joined #ruby-lang
geoffwright joined #ruby-lang
<geoffw8_> hey all
scottschecter joined #ruby-lang
havenn joined #ruby-lang
epitron joined #ruby-lang
rane_ joined #ruby-lang
ilyam joined #ruby-lang
Codif joined #ruby-lang
Axsuul joined #ruby-lang
scampbell joined #ruby-lang
ilyam joined #ruby-lang
ivorybishop|2 joined #ruby-lang
twittard joined #ruby-lang
macmartine joined #ruby-lang
amerine joined #ruby-lang
zzak joined #ruby-lang
zzak left #ruby-lang
zzak joined #ruby-lang
gix joined #ruby-lang
Weems joined #ruby-lang
Weems joined #ruby-lang
wyhaines joined #ruby-lang
mobstersauce joined #ruby-lang
Weems joined #ruby-lang
Weems joined #ruby-lang
workmad3 joined #ruby-lang
cantonic_ joined #ruby-lang
kyrylo joined #ruby-lang
singpolyma joined #ruby-lang
flip_digits joined #ruby-lang
ohookins joined #ruby-lang
<ohookins> can someone tell me the difference between def Myclass.new() and def initialize, both in the scope of Myclass ?
<MistyM> def initialize is the method that will be called when you do Myclass.new()
<rue> You should only use #initialize.
<rue> If you need to redefine .new, you'll know.
<steveklabnik> new calls allocate and then initialize
<ohookins> steveklabnik: that makes sense, by any chance would you know an authoritative language reference for that?
<ohookins> it's obviously not easy to google for
<steveklabnik> one second
<drbrain> ohookins: ri Class#new
<ohookins> d'oh
<ohookins> of course it's that easy
<ohookins> thank you
Manhose joined #ruby-lang
<steveklabnik> more specifically. ;)
<ohookins> so if that is what is meant to happen normally, what happens to the allocate phase if you override that built-in with your own allocator?
<ohookins> (assuming that is what the def Myclass.new() is meant to do)
<steveklabnik> whatever you wrote your built-in allocator to do.
<steveklabnik> is what happens.
<drbrain> ohookins: your allocator still needs to create a ruby object
<ohookins> to be completely clear, i'm trying to understand what is going on here: http://ruby-doc.org/stdlib-1.8.7/libdoc/net/http/rdoc/Net/HTTP.html#method-c-new
<ohookins> Net::HTTP defines both HTTP.new and initialize
<Defusal> woah
empity` joined #ruby-lang
<Defusal> gets is acting real strange
<ohookins> would it be fair to say Net::HTTP overrides the allocator with one that creates a proxy object?
<drbrain> ohookins: no, it doesn't redefine ::allocate
<Defusal> test.rb:12:in `gets': No such file or directory - command_line_arg (Errno::ENOENT)
<Defusal> any ideas?
<ohookins> steveklabnik: i'm not sure what you are referring to, that's the same code i'm looking at
<ohookins> and both def HTTP.new() and def initialize() mention that neither a TCP connection nor HTTP session are opened
<steveklabnik> i couldnt actually see the Proxy call
<steveklabnik> anyway, it's fair to say that it overrides _new_ with a method that creates a proxy object
S2kx joined #ruby-lang
sepp2k joined #ruby-lang
<ohookins> if i define Myclass.new(), that seems to be called instead of initialize
<ohookins> that's about as far as i get :(
<steveklabnik> ... there's nowhere farther.
<ohookins> in that case, what is the purpose of def initialize() in that code, if it cannot be called?
<steveklabnik> nit can.
<steveklabnik> it can.
<steveklabnik> i'm not sure _where_
<steveklabnik> but n = Net::HTTP.new; n.send :initialize would call it ;)
<ohookins> of course :)
* steveklabnik isn't super familliar with the net::http source
<ohookins> it's clearly a standard language feature but i didn't even see it in my reading of metaprogramming ruby
<ohookins> confusing as hell
Nisstyre joined #ruby-lang
josh9 joined #ruby-lang
<josh9> j javascript
<ohookins> drbrain: yes, so it gives new() the chance to set the object to a proxy instead of a plain http connection
<ohookins> drbrain: still unsure of when initialize() gets called, even if i can see the utility in overriding new()
<drbrain> newobj == Class#new which calls Object::allocate then #initialize on that object
<rue> ohookins: It's a method. The default .new implementation calls it. If that's overridden, it needs to be called separately if so desired. In this case, through the alias .newobj
<ohookins> aha, that's the missing piece
<drbrain> also, Net::HTTP.Proxy returns a Class
<ohookins> so they insert a small piece of logic before calling the default allocator which then calls initialize()
<ohookins> that makes sense, finally
<ohookins> many thanks!
<drbrain> no, Net::HTTP never calls the allocator
<drbrain> … Object::allocate
<drbrain> Class#new calls Object::allocate
<ohookins> ok, fair enough
slackstation joined #ruby-lang
<drbrain> if you call Object::allocate instead of Class#new (or super from Class#new) you're probably Doing It Wrong™
havenn joined #ruby-lang
<ohookins> definitely don't want to do that, just understand this damn code!
<ohookins> but it seems i do now, so again, thanks
<drbrain> ohookins: cool
<drbrain> I should have said "super from YourClass#new"
<havenn> Ryan Dahl speech at meetup in LA last night was more about bashing Ruby than praising Node.js. GIL this, GIL that.
<steveklabnik> of course
<steveklabnik> because the GIL sucks
<steveklabnik> he's right
<injekt> drbrain: does rdoc 3.11 have tomdoc support?
<drbrain> the GIL sucks when you're writing compute-heavy ruby code, for IO-heavy it's not a very big deal
<drbrain> injekt: yes, 3.10+
<injekt> drbrain: weird, what's the cli option?
<injekt> --format ?
<injekt> snap
<drbrain> --markup
<injekt> oh
<drbrain> injekt: you may want to `rdoc --markup tomdoc --write-options`
<injekt> drbrain: that didn't do anything :)
<drbrain> DAMNIT!
<drbrain> injekt: ls .rdoc_options shows nothing?
<havenn> Jruby, Rubinius, Maglev, MacRuby have all dropped GIL, ya? So Cruby has a GIL… Didn't seem he was aware the others exist. I did like that he referred to Matz as "Some guy in Japan" though… =P
<injekt> drbrain: the file is there
<steveklabnik> hahah
<steveklabnik> yeah, i'm not sure about maglev, but the others have.
<drbrain> injekt: then it worked
<injekt> drbrain: ohh, I thought it wrote the option file AND generated the docs..
<drbrain> it just writes that file, the next run will read that file for defaults
<injekt> heh
<injekt> thanks
<injekt> now for a better doc template!
<havenn> Looks like I'm wrong about Maglev. Green threads...
<theconartist> it has MVM, though
<drbrain> havenn: green threads and GIL are orthogonal concepts
<havenn> Oops.
Manhose_ joined #ruby-lang
<drbrain> you can have M:N threading between OS threads and green threads
<drbrain> s/green/userland
<drbrain> since maglev is an enterprise-grade DB I imagine they would do something like that
<injekt> drbrain: is rdoc_options exists, will it merge current cli options passed into existing ones?
<injekt> (for that run)
<drbrain> injekt: yes
<injekt> weird
<drbrain> at least, that's what I recall writing :)
mkscrg joined #ruby-lang
<injekt> running with --main doesn't appear to work unless I'm missing something. The index.html just displays "This is the API documentation for RDoc Documentation"
<drbrain> what's your argument to --main?
<injekt> README.md
<drbrain> or do you mean "doesn't override"?
<drbrain> since rdoc doesn't parse markdown (yet) that may be the problem
<injekt> ah okay
<injekt> and no not override, I didn't use the main option yet
* drbrain tries it with a non-md file
Roujo joined #ruby-lang
<injekt> weird I thought rdoc supported markdown some time ago for this
* injekt must have been thinking of something else
<drbrain> hrm...
<drbrain> so this works: rdoc --main README.rdoc README.rdoc
<injekt> so I should use rdoc for my readme for it to work?
<drbrain> yes, or you can wait another couple months while I finish out the parser and bug Evan to make peg down 1.9 compatible
<drbrain> s/peg down/pegdown/
<injekt> yeah I'll wait, it's only a single file so maybe tomdoc.rb can handle this well enough
<drbrain> I thought you could do something like rdoc --main RDoc lib/rdoc.rb
<drbrain> but maybe I broke that?
<drbrain> (specify a class or module name)
<injekt> oh possibly, rdoc help says "NAME will be the initial page displayed." for --main, so I wouldn't know
<drbrain> I think I broke ti
<injekt> :D
gregmoreno joined #ruby-lang
<rue> Make the next one out of Ti
takaokouji joined #ruby-lang
mdel joined #ruby-lang
towski joined #ruby-lang
ohookins left #ruby-lang
jasox joined #ruby-lang
riffraff joined #ruby-lang