<RantriX>
drbrain, what would you use if you couldn't use inject? haha
<RantriX>
you would have to initialize a variable to contain the sum outside of each right?
<drbrain>
RantriX: I don't use ruby 1.8.6 anymore, so that is not a problem for me
<RantriX>
the each method*
<shachaf>
RantriX: When you're learning a new language, part of the benefit is learning new ways to think about things.
<shachaf>
By making arbitrary restrictions like that you'll just end up at a bad local optimum for what you can write in the language.
<drbrain>
RantriX: do you have some thing you do in C or another language that you want to do in ruby?
<drbrain>
if so, can you show us what that thing is?
<drbrain>
we can help guide you better that way
<shachaf>
So I recommend accepting inject and coming up with a more complicated problem if you want an answer that doesn't use inject.
chessguy has quit [Remote host closed the connection]
<RantriX>
just looking for a "for" method
forrest has joined #ruby-lang
<RantriX>
where you can initialize i to a value you want
Banistergalaxy has quit [Ping timeout: 258 seconds]
<drbrain>
RantriX: use Integer#upto
<drbrain>
or Range#each
<shachaf>
Ruby doesn't have a "for" method. Nor does C (it's syntax).
<shachaf>
If what you want is precisely a C "for" loop, you'll probably just have to split it up into three components. But probably the best solution to whatever your actual problem is is to want something else. :-)
<drbrain>
ruby has "for" syntax, but it's just a wrapper around #each
Averna has joined #ruby-lang
<shachaf>
Well, yes, for x in y. That's not related.
<drbrain>
yep
<RantriX>
thanks haha
<shachaf>
I like how both Ruby and Python have "for x in y" syntax sugar, and in both cases it translates to something that you can implement for your own types, but the mechanism is completely different.
<shachaf>
(And neither one makes it particularly easy to use the other one's mechanism... It's tricky to make them interact nicely.)
jonahR has joined #ruby-lang
wallerdev has quit [Quit: wallerdev]
bzalasky has joined #ruby-lang
<TTilus>
RantriX: please inform if you crosspost
<RantriX>
TTilus: sorry, thanks for letting me know
ritek has quit [Remote host closed the connection]
<TTilus>
np
RantriX has quit [Remote host closed the connection]
<TTilus>
(and to this day i really dont know why there are two seemingly pretty similar ruby channels)
ritek has joined #ruby-lang
<TTilus>
RantriX: i would [1, 2, 3].sum (crossposting my suggestion)
<drbrain>
TTilus: because bureaucracy
ritek has quit [Remote host closed the connection]
<TTilus>
drbrain: ?
<drbrain>
TTilus: to merge the channel requires registering one of the two channels as the "official" one with free node staff
<drbrain>
to do that you need to put a special file on ruby-lang.org
ilyam has quit [Quit: ilyam]
<TTilus>
and thats beyond reach?
<drbrain>
TTilus: not beyond reach
<TTilus>
or ppl cant agree which one would be the official?
<drbrain>
I've been meaning to find the freenode form again and contact hsbt (now that we have a new ruby-lang.org maintainer)
<drbrain>
but I have been distracted
<TTilus>
oh, but you actually are upto it!
<drbrain>
yes
<TTilus>
thats good!
tonni has quit [Read error: Connection reset by peer]
tonni_ has joined #ruby-lang
<TTilus>
\o/
dmoctezuma has joined #ruby-lang
dmoctezuma is now known as ritek
<drbrain>
sweet, I captured 131072 `ping -f` packets without dropping any!
<drbrain>
but the existing pcap wrappers are GPL or abandonware
<TTilus>
zomg
forrest has quit [Quit: Leaving]
<drbrain>
in order to do this proper the pcap thread can't block the interpreter, which the existing wrappers do
<TTilus>
do you do it evented then?
<drbrain>
no, I drop the GVL when waiting on packets then acquire it when one arrives
<drbrain>
unfortunately that means one C function turns into 7
<TTilus>
:)
<drbrain>
well, two function calls to 7
postmodern has joined #ruby-lang
<drbrain>
so there's the rb_funcall entry point, one to run GVL-free, one to interrupt that function, one for rb_ensure (that I might be able to delete), one callback for pcap to handle arriving packets, one to acquire the GVL for handoff to ruby
<drbrain>
oh, and one more for the body of rb_ensure
mistym_away has quit [Remote host closed the connection]
tbuehlmann has joined #ruby-lang
tenderlove has quit [Remote host closed the connection]
tenderlove has joined #ruby-lang
<whitequark>
yorickpeterse: ping
mahlon has quit [Ping timeout: 260 seconds]
ged has quit [Ping timeout: 260 seconds]
xcombelle has joined #ruby-lang
<yorickpeterse>
pong
<yorickpeterse>
also why the fuck am I up so early
<whitequark>
yorickpeterse: do you understand the rationale of EXPR_ENDARG and tLBRACE_ARG ?
<whitequark>
it seems to exist in order to make this expression:
<whitequark>
cmd (m) {}
<whitequark>
valid
<yorickpeterse>
probably so you can pass empty blocks to every method?
<whitequark>
no no, look
* yorickpeterse
grabs parse.y
<yorickpeterse>
oh, you mean the "cmd[SPACE](" bit?
<whitequark>
"cmd[SPACE](", _combined_ with {}
<yorickpeterse>
hmmm
<whitequark>
it's insane. look, tLPAREN_ARG is emitted when you have tIDENTIFIER, space, and "("
<whitequark>
so if you have tLPAREN_ARG and it's interpreted as a primary_expr
<whitequark>
then before the rparen of this primary_expr the parser sets the lexer state to EXPR_ENDARG
<yorickpeterse>
does Ruby actually treat `foo (bar)` as `foo(bar)` or `foo.bar`?
<whitequark>
and if it's in EXPR_ENDARG, it will emit tLBRACE_ARG instead of tLCURLY (plain '{' in parse.y)
<whitequark>
and this will make the parser attach the block {} to cmd
<whitequark>
hm.
<whitequark>
yorickpeterse: wat.
<yorickpeterse>
hm, no, it treats it as `cmd(foo)`
<whitequark>
foo (bar) is interpreted as a command `foo` with the grouped expression (primary_expr) `(bar)` passed as the single argument
xcombelle has quit [Read error: Connection reset by peer]
<whitequark>
yorickpeterse: do you know why the f parse.y has a distinct kDO_BLOCK token?
<whitequark>
I mean it parses `foo do end` with tIDENTIFIER kDO kEND just fine
paidhi has left #ruby-lang [#ruby-lang]
roobynooby has quit [Quit: Leaving]
roobynooby has joined #ruby-lang
gheraint has joined #ruby-lang
dingus_khan has joined #ruby-lang
roobynooby has quit [Client Quit]
<dingus_khan>
hi, can someone help me with a potentially stupid question?
<dingus_khan>
I'm trying to iterate over a hash to check if a key occurs more than once, and increment the integer value from 1 as many times as it appears in the hash
intellitech has quit [Quit: intellitech]
<dingus_khan>
the other thing that's confusing me is just how to read strings into the keys portion of the hash while also setting the default value to 1 each time..?
voker57 has joined #ruby-lang
voker57 has quit [Changing host]
voker57 has joined #ruby-lang
gheraint has left #ruby-lang ["Bye now o/"]
madb055 has joined #ruby-lang
havenwood has joined #ruby-lang
shtirlic has joined #ruby-lang
Nisstyre-laptop has quit [Ping timeout: 260 seconds]
Mon_Ouie has joined #ruby-lang
Mon_Ouie has quit [Changing host]
Mon_Ouie has joined #ruby-lang
dingus_khan has quit [Quit: Leaving]
swav has quit [Remote host closed the connection]
My_Hearing has joined #ruby-lang
Mon_Ouie has quit [Ping timeout: 246 seconds]
voker57 has quit [Remote host closed the connection]
madb055 has quit [Quit: Konversation terminated!]
madb055 has joined #ruby-lang
adambeynon has joined #ruby-lang
marr has joined #ruby-lang
swav has joined #ruby-lang
marr123 has joined #ruby-lang
marr has quit [Ping timeout: 252 seconds]
xxaM has quit [Remote host closed the connection]
voker57 has joined #ruby-lang
voker57 has quit [Changing host]
voker57 has joined #ruby-lang
solars has joined #ruby-lang
thufir_ has joined #ruby-lang
bart has joined #ruby-lang
bart is now known as Guest83839
idkazuma has joined #ruby-lang
idkazuma has quit [Ping timeout: 258 seconds]
jerrytgarcia has joined #ruby-lang
My_Hearing is now known as Mon_Ouie
swav has quit [Read error: Connection reset by peer]
jxie has quit [Ping timeout: 255 seconds]
stevechiagozie has joined #ruby-lang
madb055 has quit [Ping timeout: 276 seconds]
jxie has joined #ruby-lang
maxmanders has joined #ruby-lang
marr123 has quit []
<yorickpeterse>
whitequark: sadly no
benanne has joined #ruby-lang
havenwood has quit [Remote host closed the connection]
dhruvasagar has quit [Ping timeout: 264 seconds]
thufir_ has quit [Quit: Leaving.]
Ridders24 has joined #ruby-lang
<Ridders24>
Hi, im trying to parse some urls, and I get this error with mechanize: fetch': 404 => Net::HTTPNotFound for https://mobile.twitter.com/about --unhandled response (Mechanize::ResponseCodeError)
<Ridders24>
what does that mean?
<injekt>
Ridders24: it means that page returns a 404
<injekt>
and that response is unhandled
<injekt>
the error messages really give it away
lsegal has quit [Quit: Quit: Quit: Quit: Stack Overflow.]
<Ridders24>
fair enough
toretore has joined #ruby-lang
agarie has quit [Remote host closed the connection]
khaase has quit [Ping timeout: 258 seconds]
<injekt>
Ridders24: what are you trying to do exactly?
<Ridders24>
injekt: writing a web spider, and i get that when It hits certain pages
<Ridders24>
injekt: trying to work out, if theres a way for it to just carry on with the previous url, its understanding how its grabbing the urls from other pages
Spaceghost|cloud has quit [Ping timeout: 258 seconds]
justinmcp has quit [Quit: No Ping reply in 180 seconds.]
shtirlic has quit [Ping timeout: 258 seconds]
amateurhuman has quit [Ping timeout: 258 seconds]
justinmcp has joined #ruby-lang
amateurhuman has joined #ruby-lang
<injekt>
Ridders24: can you show me some code?
bryanl has quit [Ping timeout: 258 seconds]
weeb1e has quit [Quit: No Ping reply in 180 seconds.]
<injekt>
Ridders24: just rescue Mechanize::ResponseCodeError
MaddinXx has joined #ruby-lang
<injekt>
Ridders24: also, you should probably try and optimize your code a little more
<injekt>
Ridders24: You create a new mechanize instance for every single url you fetch
<injekt>
you only need one agent
<Ridders24>
you mean instead of using rwspider to fetch the url and mech to parse it?
<injekt>
Ridders24: no you can still use rwspider (although I'm not sure I see the point in using both rwspider and mechanize, but I haven't used/seen rwspider before
<injekt>
I would just use mechanize myself
<injekt>
because the pages you fetch via mechanize aren't going to use the rwspider options
<Ridders24>
i think i did it as i was still trying to get to grips with mechanize, I'll probably rewrite that section
maxmanders has quit [Quit: Computer has gone to sleep.]
<injekt>
Ridders24: you're literally just fetching urls and storing any whos body match some criteria?
<Ridders24>
injekt: yh basically
jerrytgarcia has quit [Read error: Connection reset by peer]
jerrytgarcia has joined #ruby-lang
jerrytgarcia has quit [Client Quit]
<injekt>
Ridders24: mechanize can do things like this quite easily, just fetch the page and traverse the links in it.
<injekt>
Ridders24: just google 'mechanize web spider' and you'll see lots of answers
toretore has quit [Ping timeout: 260 seconds]
toretore has joined #ruby-lang
<Ridders24>
injekt: thanks for the help, appreciate it
<yorickpeterse>
whitequark: do you know of a reliable way to extract method argument types and their names? #parameters is unreliable as fuck
stevechiagozie has quit [Quit: Computer has gone to sleep.]
<yorickpeterse>
e.g. `Kernel.method(:test).parameters` => [[:rest]], while it has 2 required arguments and 1 optional one
<yorickpeterse>
Ruby 2.0 sadly doesn
<yorickpeterse>
* doesn't fix this
<whitequark>
yorickpeterse: that is not possible.
<whitequark>
it works through rb_scan_args
<whitequark>
which can not be reflected upon.
<yorickpeterse>
hmpf
<yorickpeterse>
So far I've been relying on `ri` for info, but it's a bit of a PITA
<apeiros>
anybody have a good regex for "%{foo}" style templates? It should not match escaped ones, e.g. "\\%{foo}" should not match, "\\\\%{foo}" should match again…
<whitequark>
the point here is that a humble "do" in ruby could mean three (yes three) different things
<yorickpeterse>
kDO_LAMDA is probably `lambda do; end`
<whitequark>
yorickpeterse: nope
<yorickpeterse>
wat
<whitequark>
lemme explain.
<whitequark>
kDO_BLOCK is `m do end`. kDO_COND is `while true do end`. kDO_LAMBDA is `-> do end`.
<whitequark>
kDO is either the same as kDO_BLOCK or kDO_COND.
<whitequark>
as I understand it.
<yorickpeterse>
hm
stevechiagozie has joined #ruby-lang
<whitequark>
the point here is that you can have `while m do end`
<whitequark>
or `while -> do end`
<whitequark>
it would probably make *much* more sense to just kill the `while..do` loop form, but we have what we have.
stevechiagozie has quit [Client Quit]
apeiros is now known as apeiros_
<whitequark>
sooo, to disambiguate this, ruby's lexer has the so-called 'stack states'. it's basically a stack of bits.
<whitequark>
it has four operations: push, pop, top? (which do what you expect), and also lexpop
<whitequark>
`def lexpop; a, b = pop, pop; push a || b; end`
<whitequark>
I have no clue as to why lexpop exists or what exactly does it do, semantically.
<whitequark>
so, parser pushes and pops stuff to the two stacks called `cond` and `cmdarg`, and lexer consults it to determine if it should emit kDO, kDO_BLOCK, kDO_LAMBDA or whatever else
<whitequark>
oh there is also a boolean flag called `command_start` which does something, but they killed it in jruby with no visible effect, so I guess I could kill it either.
<whitequark>
that's all what is left to implement in order to have a complete lexer.
postmodern has quit [Quit: Leaving]
<whitequark>
also while we're at it...
<whitequark>
>> while m do end
<eval-in>
whitequark => /tmp/execpad-05d2cb283f83/source-05d2cb283f83:2:in `<main>': undefined local variable or method `m' for main:Object (NameError) (http://eval.in/13540)
<whitequark>
I'm not sure what is worse: php's parser which doesn't have a formal grammar, or ruby's parser which implements a certain formal grammar in such a horrible way
srbaker has quit [Quit: Computer has gone to sleep.]
Mon_Ouie has joined #ruby-lang
Mon_Ouie has joined #ruby-lang
Mon_Ouie has quit [Changing host]
<whitequark>
oh also ->{ is tLAMBDA tLAMBEG, and ->do is tLAMBDA kDO_LAMBDA
<whitequark>
it probably cannot use simple tLBRACK because bison
<yorickpeterse>
also, that's 7 years old, not sure how relevant that would be today
<whitequark>
yorickpeterse: it is relevant, judging by machine translation and code references
<yorickpeterse>
hmm
<khaase>
how come there is no destructive version of take_while?
<whitequark>
I just need to precisely understand what did they have in mind while writing that code
<khaase>
ie shift_while
srbaker has joined #ruby-lang
<yorickpeterse>
well, I can send you my copy of "Genki: Elementary Japanese" :D
<whitequark>
khaase: because Enumerable generally does not support destructive operations?
<whitequark>
yorickpeterse: fuck that, I need it *now*.
refd has joined #ruby-lang
<khaase>
whitequark: I'm talking about arrays
<yorickpeterse>
haha
stevechiagozie has joined #ruby-lang
srbaker has quit [Client Quit]
<MaddinXx>
so I just ask. I've created a Rake multitask which "fires" 3 tasks at the same time (guard-livereload (via shell), serve (via shell) and rb-fsevent). problem is that CTRL+C doesn't quit all of them, e.g. LiveReload keeps watching. any hints on how to solve that? Rakefile: https://github.com/MaddinXx/frontrake/blob/develop/Rakefile
<MaddinXx>
lin e 113
TheNotary has quit [Ping timeout: 264 seconds]
dhruvasagar has joined #ruby-lang
benanne has quit [Read error: Connection reset by peer]
refd has quit [Max SendQ exceeded]
refd has joined #ruby-lang
MartynKeigher has quit [Excess Flood]
bart has joined #ruby-lang
bart is now known as Guest86526
srbaker has joined #ruby-lang
workmad3 has joined #ruby-lang
srbaker has quit [Client Quit]
MartynKeigher has joined #ruby-lang
kristofferrr has joined #ruby-lang
benanne has joined #ruby-lang
Guest86526 has quit [Ping timeout: 258 seconds]
slyphon has quit [Quit: slyphon]
refd has quit [Read error: Connection timed out]
CoverSlide has quit [Read error: Connection reset by peer]
workmad3 has quit [Ping timeout: 264 seconds]
volov has joined #ruby-lang
<whitequark>
yorickpeterse: haha I found a translator dude who can do it
<whitequark>
I mean literally, he's @TranslatorDude
<yorickpeterse>
hah
toertore has joined #ruby-lang
<whitequark>
god why do I have to do this -_-
toretore has quit [Ping timeout: 255 seconds]
MaddinXx has quit [Remote host closed the connection]
voker57 has quit [Read error: Connection reset by peer]
bzalasky has joined #ruby-lang
plusk has joined #ruby-lang
plusk has quit [Client Quit]
plusk has joined #ruby-lang
dhruvasagar has quit [Ping timeout: 245 seconds]
benwoody has left #ruby-lang [#ruby-lang]
Mon_Ouie has quit [Ping timeout: 256 seconds]
marr has joined #ruby-lang
mistym_away has joined #ruby-lang
tbuehlmann has quit [Remote host closed the connection]
dhruvasagar has joined #ruby-lang
realDAB has quit [Quit: realDAB]
madb055 has quit [Ping timeout: 248 seconds]
madb055 has joined #ruby-lang
madb055 has quit [Read error: No route to host]
madb055 has joined #ruby-lang
jxie_ has quit [Quit: leaving]
methods has joined #ruby-lang
tomzx_mac has joined #ruby-lang
intellitech has joined #ruby-lang
valeri_uF0 has left #ruby-lang [#ruby-lang]
sio has left #ruby-lang ["WeeChat 0.4.0"]
valeri_ufo has joined #ruby-lang
methods has left #ruby-lang [#ruby-lang]
xcombelle has joined #ruby-lang
dhruvasagar has quit [Ping timeout: 264 seconds]
jacky has quit [Excess Flood]
plusk has left #ruby-lang [#ruby-lang]
bart has joined #ruby-lang
bart is now known as Guest19752
banister`sleep has joined #ruby-lang
realDAB has joined #ruby-lang
Guest19752 has quit [Ping timeout: 252 seconds]
srbaker has joined #ruby-lang
<whitequark>
yorickpeterse: ok it's a deal
JohnBat26 has joined #ruby-lang
<whitequark>
I'll pay that guy to translate chapter 11 of ruby hacking guide to english
madb055 has quit [Ping timeout: 256 seconds]
<yorickpeterse>
haha
<yorickpeterse>
I'll buy you a crate of beer if you end up writing something nice with this
<whitequark>
cost me ~$500... well, it's japanese after all
<yorickpeterse>
let the company pay for it :D
Guest76236 has joined #ruby-lang
<whitequark>
well I guess.
<whitequark>
also down to 1 failed lexer test
<whitequark>
and 75 failures, 316 errors on parser tests
<whitequark>
from ~900 of them
<whitequark>
wtf why does it think yield is a tIDENTIFIER >_<
<whitequark>
55/316!
* yorickpeterse
is currently hacking on Rbx
<yorickpeterse>
took me a good 2 hours but I'm getting there
swav has quit [Remote host closed the connection]
swav has joined #ruby-lang
fire has joined #ruby-lang
bzalasky has quit [Remote host closed the connection]
slyphon has joined #ruby-lang
banister`sleep has quit [Read error: Connection reset by peer]
sush24 has quit [Quit: Leaving]
sush24 has joined #ruby-lang
TheNotary has joined #ruby-lang
r0bglees0n has quit [Ping timeout: 245 seconds]
Mon_Ouie has joined #ruby-lang
realDAB has quit [Quit: realDAB]
Ridders24 has quit [Ping timeout: 245 seconds]
Ridders24 has joined #ruby-lang
Guest___ has joined #ruby-lang
bart has joined #ruby-lang
bart is now known as Guest82852
pkrnj has joined #ruby-lang
dRbiG has joined #ruby-lang
volov has quit [Remote host closed the connection]
bzalasky has joined #ruby-lang
swav has quit [Remote host closed the connection]
volov has joined #ruby-lang
soknee has joined #ruby-lang
swav has joined #ruby-lang
volov has quit [Ping timeout: 256 seconds]
soknee has quit [Ping timeout: 252 seconds]
Guest___ has quit [Ping timeout: 252 seconds]
bzalasky has quit [Remote host closed the connection]
maxmanders has joined #ruby-lang
Ridders24 has quit [Quit: Leaving]
Ridders24 has joined #ruby-lang
volov has joined #ruby-lang
alessio_rocco has joined #ruby-lang
hashbangchris has joined #ruby-lang
<Ridders24>
injekt: I followed your advice, and rewrote my spider, however I can't seem to work out, how to get the keyword searching bit to work. when I do page.search('a').each do |kword|, as an example it returns hrefs within the page, however when i do page.search('ruby').each do |kword|, I don't get anything back, why?
Guest82852 has quit [Remote host closed the connection]
swav has quit [Remote host closed the connection]
sush24 has quit [Quit: This computer has gone to sleep]
<Ridders24>
canton7: do i need to do somthing like <body> Ruby
<canton7>
Ridders24, what are you searching for?
<Ridders24>
particular words, that might appear in the text of a webpage
<canton7>
just wanting to see if the page contains the keyword?
<Ridders24>
yh
<canton7>
why are you using nokogiri then?
<Ridders24>
why not?
<canton7>
nokogiri's for parsing the document, and allowing you to select specific elements. so if you were looking for all of the links in the page with class 'foo', nokogiri's your tool
<canton7>
or maybe you're after the contents of the <nav> tag, etc...
<zzak>
you could find links with Ruby in the text
<zzak>
but it must be a link
<Ridders24>
ah ok, I did use mechanize earlier for searching and it seemed to work fine, it was just when i rewrote the script i didnt use it and thought nokogiri did the same thing
<canton7>
mechanize uses nokogiri I believe, but it also handles cookies, redirects, etc
xcombelle has quit [Ping timeout: 256 seconds]
<zzak>
yup
brianpWins has joined #ruby-lang
hashbangchris has quit [Quit: mt]
tenderlove has quit [Remote host closed the connection]
tenderlove has joined #ruby-lang
dc5ala has quit [Quit: Ex-Chat]
xcombelle has joined #ruby-lang
skade has joined #ruby-lang
<khaase>
any rspec pros around?
pkrnj has quit [Quit: Computer has gone to sleep.]
<andrewvos>
khaase: I've used it a bit.
<andrewvos>
Though I'm probably quite rusty on the topic
<khaase>
andrewvos: do you know if and how I can chain to a builtin matcher?
<khaase>
ie I'd like the check the matched parts with a match helper
<andrewvos>
No idea sorry
<khaase>
no worries
<khaase>
it's pretty specific I guess
<zzak>
khaase: quick question
<khaase>
QUICK!
<khaase>
ok :)
<zzak>
khaase: how come ruby-head on travis is 2.0.0-dev?
<zzak>
and where do i report bugs like this
<khaase>
zzak: because we suck at updating
<khaase>
zzak: either issue tracker or support@travis-ci.org
<zzak>
which one :(
<khaase>
zzak: travis-ci/travis-ci
<zzak>
you got it
<zzak>
khaase: thanks :D
<khaase>
zzak: I don't know, tbh, I thought joshk and the guy from rvm built something so we don't have to rebuild our vms to update ruby, but I guess we're not using that for mri
pkrnj has joined #ruby-lang
Nisstyre has quit [Ping timeout: 264 seconds]
<zzak>
the rvm version is only a week or two old
<khaase>
binary build?
<khaase>
dunno, please bother josh
<khaase>
I'm trying to bother people about this right now, too
alessio_rocco has quit [Ping timeout: 264 seconds]
<dingus_khan>
hi, is there a way to read string inputs into a hash as keys, and set the value to integer 1, but if the same string is entered again, the value gets incremented while in the loop?
ryanf_ has joined #ruby-lang
<dingus_khan>
in other words, I can't figure out how to properly read strings into a hash as keys and set a default value and then increment that..?
srbaker has quit [Quit: Computer has gone to sleep.]
<canton7>
then with whatever you read, myhash[key] += 1
<skade>
In the specific case of numbers, you can also use `Hash.new(0)`
<dingus_khan>
ok, so the second part, I place that after I get the string from the input? as in, myash[gets.chomp] +=1 ?
<dingus_khan>
sorry, I am utter noob
voker57 has joined #ruby-lang
skade has quit [Quit: Computer has gone to sleep.]
<canton7>
aye
<dingus_khan>
so that will work, what I put there?
<canton7>
yes
<canton7>
assuming I've understood what you're trying to do
sepp2k has quit [Quit: Leaving.]
<dingus_khan>
ok, so I'm trying to read in strings from user input until exit condition is met, and each string that's read in is placed in an otherwise empty hash as a key, and the value is set by default to 1, and then a check is run on the hash to see if that key already exists, and if it does, instead of placing it in the hash again, the value of the duplicate string item is just incremented. it's incremented as many times as the same string is input. does
<dingus_khan>
that make sense?
<canton7>
yup, and that's what my suggestion does
<dingus_khan>
all before exiting the input loop
<dingus_khan>
ok, sweet baby t-rex, thank you!
<canton7>
well, you'll have the check the exit condition of course
<dingus_khan>
right, I'll do that before any of the hash stuff, just check for the "done" string or something
swav has joined #ruby-lang
<canton7>
hashes have a default value, which is returned if the specified key doesn't exist. by default that's nil, so myhash['key_that_doesnt_exist'] returns nil
<canton7>
you can also set it to be anything else - here, we set the default value to 0
<canton7>
so hash['key_that_doesnt_exist'] returns 0
<canton7>
so calling hash['key_that_doesnt_exist'] += 1 grabs the value for that key - default 0 - before incrementing it and setting it back into the bash
<dingus_khan>
wait, I thought you could create an empty hash with no values in it?
<canton7>
yes
<canton7>
we create an empty hash with no keys or values, but with a custom default value
<dingus_khan>
ohhh, in the example you gave me then, right? because the first part I read on hashes was you could just create hash = Hash.new with nothing in it, or did I misread that?
<canton7>
that's right
<canton7>
well, you'd normally write hash = {}, but it means the same thing
<canton7>
but like I keep saying, you can create an *empty* hash, but which has a default value which is *not* the (normal) nil
<dingus_khan>
oh man, thank you, sorry for my thick skull, I don't know why I wasn't getting that until just now--that's exactly what I wanted to do, but I wasn't sure how or it really worked that way
<dingus_khan>
if it*
<canton7>
coolies
swav has quit [Ping timeout: 264 seconds]
punchfac_ has joined #ruby-lang
holgerno has joined #ruby-lang
<canton7>
this would be an alternaitve that didn't use the default value feature
<dingus_khan>
if I wanted to ask if someone could look at a chunk of code that isn't working for me for a reason I don't understand, would I use gist? I'm completely new to IRC, sorry
<dingus_khan>
lol, I'm too slow
punchfacechamp has quit [Ping timeout: 248 seconds]
<dingus_khan>
wait, so this part here: if hash.has_key?(mykey) --> hash[mykey] = 1 ; that part sets the value to 1 if there is no identical string already in the hash, right?
maxmanders has joined #ruby-lang
punchfac_ has quit [Ping timeout: 252 seconds]
<dingus_khan>
because it looks like if has_key? returns true, then it only sets the value to 1 but a false is the increment one?
punchfacechamp has quit [Read error: Connection reset by peer]
punchfacechamp has joined #ruby-lang
sepp2k has joined #ruby-lang
<dingus_khan>
I'm not sure why this isn't working, but I'm guessing it's because I can't use that string variable as the check condition for has_key?, but how else would you check the string against the hash keys? -> http://pastie.org/7102396
punchfac_ has joined #ruby-lang
maxmanders has quit [Quit: Computer has gone to sleep.]
punchfacechamp has quit [Ping timeout: 245 seconds]
volov has quit [Remote host closed the connection]
volov has joined #ruby-lang
<andrewvos>
Should the enumeration of every_url and every_failed_url be not nested?
madb055 has quit [Read error: Connection reset by peer]
<andrewvos>
I mean, every_failed_url shouldn't be inside every_url
<Ridders24>
ok i can change that, but thats not causing the issue is it?
<andrewvos>
Well it would be requesting the failed urls a lot more than it should as far as I can see
volov has left #ruby-lang [#ruby-lang]
volov has joined #ruby-lang
<Ridders24>
what the 404 error?
dingus_khan has joined #ruby-lang
<Ridders24>
injekt mentioned about using rescue WWW::Mechanize::ResponseCodeError, but i couldnt get it to work
<TheNotary>
should "working_urls" be renamed to "working_url" as that it's one instance of a group of urls you're iterating through? I might be misreading your code a bit.
stevechiagozie has quit [Quit: Computer has gone to sleep.]
<Ridders24>
ezkl: that just highlights the 404 page? is doesnt ignore it and carry on searching
<Ridders24>
?
<TheNotary>
you'd think mechanize would be structured in a way where it returns an object with a response code that equaled 404 instead of raising an exception. Does anyone else find that funky?
<TheNotary>
Ridders24, what happens when instead of doing `puts "Rescued!" you do `next`?
<TheNotary>
I honestly can't say I've tried using next within a file.open loop though, heh
<Ridders24>
I'll try it and see
<ezkl>
You'll want to use an ary as a bad URI stack or something
<drbrain>
Ridders24: you should only create one mechanize instance
mjio has joined #ruby-lang
<Ridders24>
whys that?
brianpWins has quit [Quit: brianpWins]
<drbrain>
Ridders24: mechanize will reuse HTTP connections which improves performance
<drbrain>
also, mechanize creates a lot of objects when starting up
<drbrain>
so all those need to be GC'd if you create an instance then immediately throw it away
bzalasky has joined #ruby-lang
<Ridders24>
ahh ok
xalei has joined #ruby-lang
pkrnj has joined #ruby-lang
xalei has quit [Client Quit]
<TheNotary>
I'm having a minor problem with non-primitive objects... You know how when you make a hash, calling it h. and then you do `f = h` now f and h are the same thing? How do you prevent that? I thought .dup would work but apparently not... http://pastebin.com/EyhvT0We
<drbrain>
TheNotary: dup is shallow
<drbrain>
it duplicates the hash, not its entries
<TheNotary>
oh, that makes sense
<TheNotary>
is there a shortcut for doing a deeper .dup?
<TheNotary>
or do I need to traverse the nodes
<drbrain>
Marshal.load Marshal.dump hash
<drbrain>
provided you don't have a default block and all the entries are dumpable
<TheNotary>
thanks! They should dump ok i think.
wudofyr has quit [Remote host closed the connection]
wudofyr has joined #ruby-lang
srbaker has joined #ruby-lang
havenwood has quit [Remote host closed the connection]
srbaker has quit [Quit: Computer has gone to sleep.]