ChanServ changed the topic of #ruby-lang to: Ruby 1.9.3-p125: http://ruby-lang.org | Paste >3 lines of text on http://pastie.org or use a gist
achiu has joined #ruby-lang
berth_ has quit [#ruby-lang]
shevy has joined #ruby-lang
jmontross has joined #ruby-lang
Fullmoon has joined #ruby-lang
burns180_ has joined #ruby-lang
tenderlove has joined #ruby-lang
leonL has joined #ruby-lang
chimkan_ has joined #ruby-lang
havenn has joined #ruby-lang
ascarter has joined #ruby-lang
postmodern has joined #ruby-lang
Luxx_ has joined #ruby-lang
burns180 has joined #ruby-lang
bousquet has joined #ruby-lang
justinxreese has joined #ruby-lang
workmad3 has joined #ruby-lang
slyphon has joined #ruby-lang
kek1 has joined #ruby-lang
andkerosine has joined #ruby-lang
<andkerosine> Is it possible for a splat parameter to take default values?
dhruvasagar has joined #ruby-lang
burns180 has joined #ruby-lang
Heimidal has joined #ruby-lang
Joeysomo has joined #ruby-lang
Joeysomo has joined #ruby-lang
justinxreese has joined #ruby-lang
burns180_ has joined #ruby-lang
<shevy> andkerosine I tried that recently
<shevy> def foo(*input = ARGV)
<shevy> does not seem to work
<shevy> Mon_Ouie suggested to put the stuff within the method body, but I don't like ARGV within any method body
jredville has joined #ruby-lang
slimfit has joined #ruby-lang
heppy_ has joined #ruby-lang
shtirlic_ has joined #ruby-lang
burns180 has joined #ruby-lang
<andkerosine> shevy: It seems that's what I'll have to do unfortunately.
<andkerosine> What's the most convenient way to mix #select with #pop/#shift?
<erikh> don
<erikh> don't
looopy has joined #ruby-lang
<erikh> select is good for pipelines, exploit that and do your mutation in other steps.
<andkerosine> Fair enough.
<andkerosine> Hm... actually, I think it might be fitting here.
<andkerosine> I'm building a request, and it takes a *params argument.
<andkerosine> A potential set of parameters might be [50, 'hot', 'year', 120000]
<andkerosine> Which means grab 50 reddit posts sorted by hot and year, and cache the results for two minutes.
<andkerosine> I'd like to be able to select the first parameter out as the count, and then remove it so that the next match is the cache length, which may or may not be present.
Joeysomo_ has joined #ruby-lang
jkyle has joined #ruby-lang
<erikh> can you just subscript?
<erikh> or just do your mutation first
<erikh> count, length = a.shift, a.pop; do_stuff_with(a)
burns180_ has joined #ruby-lang
<andkerosine> I don't know that it's so straightforward.
<erikh> well if that's what your array looks like...
<andkerosine> I'm making it harder on me to make it easier for the user. I'd like for them to be able to pass in params pretty much however they choose.
<andkerosine> So I'm trying to make my code correctly parse out what they're trying to grab.
<andkerosine> I reckon just taking any integer greater than 1000 to be the cache length is simplest.
<erikh> unless you're an expert in NLP "however they choose" is a waste of time
<erikh> it'll also slow down your code
<erikh> be lazy enough to document your API and point users to it when they have problems.
<erikh> -- Larry Wall
kek1 has joined #ruby-lang
<andkerosine> Alas, it's in my nature to mix the two. : /
<andkerosine> Freedom of expression + guidelines on best practices.
<andkerosine> That's... sort of the Ruby way, no?
igotnolegs has joined #ruby-lang
machine1 has joined #ruby-lang
<erikh> people will exploit your documentation no matter what you do
<erikh> but in the most liberal of interpretations you're describing NP-complete problems at best, and needlessly so
<erikh> don't try to make the magic formula; just make your library solid and the API will sort itself out
macmartine has joined #ruby-lang
dhruvasagar has joined #ruby-lang
machine1 has joined #ruby-lang
burns180 has joined #ruby-lang
mikeric has joined #ruby-lang
gjaldon has joined #ruby-lang
wmoxam has joined #ruby-lang
Joeysomo has joined #ruby-lang
burns180_ has joined #ruby-lang
Weems has joined #ruby-lang
Weems has joined #ruby-lang
joast has joined #ruby-lang
tomzx has joined #ruby-lang
burns180 has joined #ruby-lang
aza_kibo_ has joined #ruby-lang
rohit has joined #ruby-lang
jkyle has joined #ruby-lang
phlipper has joined #ruby-lang
mistym has joined #ruby-lang
chessguy has joined #ruby-lang
headius has joined #ruby-lang
burns180_ has joined #ruby-lang
tyman_ has joined #ruby-lang
looopy has joined #ruby-lang
wmoxam has joined #ruby-lang
mtkd has joined #ruby-lang
looopy has joined #ruby-lang
DRCALKIN has joined #ruby-lang
bglusman has joined #ruby-lang
burns180 has joined #ruby-lang
fayimora_ has joined #ruby-lang
flebel has joined #ruby-lang
Joeysomo has joined #ruby-lang
Joeysomo_ has joined #ruby-lang
macmartine has joined #ruby-lang
takaokouji has joined #ruby-lang
twittard has joined #ruby-lang
butchanton has joined #ruby-lang
gregmoreno has joined #ruby-lang
burns180_ has joined #ruby-lang
neoesque has joined #ruby-lang
srbaker has joined #ruby-lang
<dhruvasagar> Utkarsh: there?
Aengus has joined #ruby-lang
fredguest has joined #ruby-lang
Nisstyre has joined #ruby-lang
hagabaka has joined #ruby-lang
burns180 has joined #ruby-lang
solars has joined #ruby-lang
ascarter has joined #ruby-lang
gmurphey has joined #ruby-lang
darkf_ has joined #ruby-lang
bousquet has joined #ruby-lang
savage- has joined #ruby-lang
tyman has joined #ruby-lang
dhruvasagar has joined #ruby-lang
burns180_ has joined #ruby-lang
yxhuvud has joined #ruby-lang
rohit has joined #ruby-lang
x0F_ has joined #ruby-lang
gokul has joined #ruby-lang
srbaker has joined #ruby-lang
dhruvasagar_ has joined #ruby-lang
tudorstudio has joined #ruby-lang
brownies has joined #ruby-lang
deryldoucette has joined #ruby-lang
burns180 has joined #ruby-lang
butchanton has joined #ruby-lang
langbiangplaza has joined #ruby-lang
langbiangplaza has joined #ruby-lang
uniqanomaly has joined #ruby-lang
heppy has joined #ruby-lang
burns180_ has joined #ruby-lang
langbiangplaza has joined #ruby-lang
Heimidal has joined #ruby-lang
wyhaines has joined #ruby-lang
havenn has joined #ruby-lang
burns180 has joined #ruby-lang
srbaker has joined #ruby-lang
brianpWins has joined #ruby-lang
machine1 has joined #ruby-lang
achiu has joined #ruby-lang
rippa has joined #ruby-lang
burns180_ has joined #ruby-lang
csherin has joined #ruby-lang
davidw has joined #ruby-lang
TvL2386 has joined #ruby-lang
<TvL2386> hi guys,
justinmcp has joined #ruby-lang
Luxx_ has joined #ruby-lang
Z33K|Lux has joined #ruby-lang
burns180 has joined #ruby-lang
solars has joined #ruby-lang
<TvL2386> hi guys, I'm having problems with nokogiri. On my development machine it works perfectly and on my production machine it does not. I'm using bundler to maintain gem versions and I am using ruby-1.9.3p125. A little script to simulate is here: http://pastie.org/3510031 The output on dev/prod differ (shown in comments in the pastie)
Natch has joined #ruby-lang
mikeric has joined #ruby-lang
mikeric has joined #ruby-lang
tbuehlmann has joined #ruby-lang
ezkl has joined #ruby-lang
burns180_ has joined #ruby-lang
kek1 has joined #ruby-lang
<Defusal> anyone ever use X-Accel-Redirect with nginx?
thrcka has joined #ruby-lang
<TvL2386> darn, I needed to do data.encode!("utf-8","ISO-8859-1") for some reason I don't understand. Guess it has something to do with default encoding differences on the 2 boxes?
postmodern has joined #ruby-lang
mikeric has joined #ruby-lang
Natch| has joined #ruby-lang
pemeon has joined #ruby-lang
burns180 has joined #ruby-lang
<Mon_Ouie> That means "encode from UTF-8 to ISO-8859-1"
adambeynon has joined #ruby-lang
adambeynon has joined #ruby-lang
<TvL2386> Mon_Ouie, that's obvious, but why does it have to be done on production to get it to function the same as development?
<TvL2386> Also, anyone here familiar with ruby-inotify?
flebel has joined #ruby-lang
kitallis has joined #ruby-lang
burns180_ has joined #ruby-lang
francisfish has joined #ruby-lang
gentz has joined #ruby-lang
tekin has joined #ruby-lang
amerine has joined #ruby-lang
<Mon_Ouie> I'd guess locales may be different on those machines
<Mon_Ouie> Which would change the default encoding
burns180 has joined #ruby-lang
uniqanomaly has joined #ruby-lang
rohit has joined #ruby-lang
toretore has joined #ruby-lang
kp666 has joined #ruby-lang
thrcka has joined #ruby-lang
burns180_ has joined #ruby-lang
<Stereokitsune> Hello.
<Stereokitsune> I forgot how this piece of shit^Wcode may be optimized:
<Stereokitsune> return "%d.%02d.%d, %02d:%02d" % [date.day, date.month, date.year, date.hour, date.min]
<Stereokitsune> (yes, I'm just a newbie in Ruby)
<uniqanomaly> date.strftime "%d.%m.%y %H:%M"
PatrixCR has joined #ruby-lang
<manveru> uniqanomaly: you mean %Y :)
<uniqanomaly> ah yea
<Stereokitsune> Oh, thanks.
mytrile has joined #ruby-lang
<PatrixCR> guys, what's the difference of cucumber, rspec, capybara, and selenium?
burns180 has joined #ruby-lang
mssola has joined #ruby-lang
manojhans has joined #ruby-lang
looopy has joined #ruby-lang
apeiros_ has joined #ruby-lang
rob_ has quit [#ruby-lang]
jamw has joined #ruby-lang
burns180_ has joined #ruby-lang
FortKnox has joined #ruby-lang
csherin has joined #ruby-lang
manojhans has joined #ruby-lang
benanne has joined #ruby-lang
andkerosine has joined #ruby-lang
<andkerosine> If the method signature is something like def inbox(folder = 'inbox', count), how does one go about making it so that inbox(5) doesn't pass 5 to the folder argument?
<andkerosine> I imagine it involves having the single argument be a splat and then parsing out the values?
publicvoid__ has joined #ruby-lang
<PatrixCR> inbox nil, 5
<andkerosine> Yep, unpleasant for the user.
<PatrixCR> inbox 'inbox', 5
<andkerosine> Redundant.
<PatrixCR> switch the argument position, then
m3nd3s has joined #ruby-lang
<andkerosine> That's counter-intuitive.
<andkerosine> I don't mind sacrificing a bit of programmer pleasantness to increase user pleasantness.
<andkerosine> Just wondering if there was a non-splat way to do it.
<PatrixCR> inbox count: 5
<PatrixCR> inbox :count => 5
<andkerosine> All viable options, of course, but they don't maximize user pleasantness, which is my primary aim.
<dominikh> then you're doomed, because those are your only options.
<andkerosine> Not at all.
<andkerosine> A splat works fine.
<dominikh> which is one of the mentioned options. so use it?
<andkerosine> This was a question of curiosity, not a dead end.
<andkerosine> Why is the pursuit of surplus knowledge so frowned upon?
<dominikh> it's not, ignoring "there is no other way" is.
<dominikh> change the order, explicitly pass nil, use a hash, use a splat. those are your options.
<dominikh> if you don't like any of these, bad luck.
<andkerosine> Duly noted.
<andkerosine> I thought there might be some clever Ruby approach to matching on argument types.
<PatrixCR> who is your "user" anyway?
<rippa> andkerosine: def inbox(folder, count = 'inbox'); count, folder = folder, count
postmodern has joined #ruby-lang
<andkerosine> rippa: That's just a little too convoluted for my tastes. Clever, but not very clear.
<andkerosine> PatrixCR: I'm writing a wrapper around the reddit API.
<andkerosine> Ruby allows for quite a bit of freedom of expression, and I'd like to do the same.
kain has joined #ruby-lang
<andkerosine> Would any of that be considered "bad practice"?
<apeiros_> yes
<apeiros_> see Enumerable#find
<andkerosine> Just... to avoid the subscripting?
<apeiros_> and: eeeeew!
<Mon_Ouie> p.to_i == p ?
<andkerosine> To pull out the count.
<apeiros_> .is_a?(String), (Integer)
<apeiros_> but still, horrible
<andkerosine> Same thing.
<Mon_Ouie> I'd just have a fixed order
<Stereokitsune> Is there the better way to replace symbols &, <, > and other ones into HTML sequences (like &amp) except of manual composing of hundred regexps?
<Mon_Ouie> Stereokitsune: CGI.escape_html
<apeiros_> it's actually one regexp @ Stereokitsune
<apeiros_> and Mon_Ouie means escapeHTML (bad bad form in stdlib :-S)
<Mon_Ouie> Nope
<Mon_Ouie> Both work
<apeiros_> oh? they've added a sane one?
<apeiros_> good to know. *takes not to refactor all .escapeHTML in his code*
<Stereokitsune> Thank you.
<PatrixCR> and: do you use ruby 1.9?
<andkerosine> Well, I'd also like to support 1.8.7 in this case.
<PatrixCR> Hm. In ruby 1.9.3 in my machine, I create a method just like you wrote, and when I call inbox 5, the count parameter has the value 5, and folder is 'inbox'
manojhans has joined #ruby-lang
<PatrixCR> maybe ruby 1.8 doesn't support it?
<andkerosine> Huh...
<andkerosine> I could /swear/ I tested that.
thone_ has joined #ruby-lang
manojhans has joined #ruby-lang
burns180 has joined #ruby-lang
<andkerosine> PatrixCR: Thanks. Alas, syntax error in 1.8.
rohit has joined #ruby-lang
<shevy> hehe
rob_ has joined #ruby-lang
<rob_> hi
wyhaines has joined #ruby-lang
<rob_> if i have class that inherits from Hash, how can i load the value of another hash into the class?
workmad3 has joined #ruby-lang
<apeiros_> rob_: you mean into an instance of your class?
<rob_> yeah
<apeiros_> yh = YourHash.new; yh.replace(some_hash)
<rob_> ahh thanks
burns180 has joined #ruby-lang
Joeysomo has joined #ruby-lang
steeljav has joined #ruby-lang
<andkerosine> So, JSON#parse ignores comments just fine, but is there a way to keep them?
langbiangplaza has joined #ruby-lang
futurechimp has joined #ruby-lang
machine2 has joined #ruby-lang
<andrewvos> andkerosine: I'm just going to say "No", but that may be unfounded.
<andkerosine> Looks like yajl-ruby can do it.
<rue> rob_: You should nearly always use composition rather than inheritance when dealing with collections
<rue> Instead of*
manojhans has joined #ruby-lang
dous has joined #ruby-lang
<rob_> rue: not sure i understand what you mean :)
burns180_ has joined #ruby-lang
<rue> Has a, not is a
<dominikh> in layman terms: do not inherit from Hash, have an instance of Hash in your class
<rob_> ahh thanks :)
<rob_> i used to do it that way but it's nice to have access to the hash methods on your class
<dominikh> rob_: forward the methods. and things like #select will have to be modified, anyway, because they would return instances of Hash otherwise
<rob_> is there a simple way to forward methods?
<rob_> thanks for the advice :)
<dominikh> (or method_missing + respond_to? if you do not want to explicitly say which methods should forward)
havenn has joined #ruby-lang
imperator has joined #ruby-lang
looopy has joined #ruby-lang
future_chimp has joined #ruby-lang
solars has joined #ruby-lang
PatrixCR has quit [#ruby-lang]
chessguy has joined #ruby-lang
burns180 has joined #ruby-lang
chimkan has joined #ruby-lang
theoros has joined #ruby-lang
chimkan_ has joined #ruby-lang
ezkl has joined #ruby-lang
sandbags has joined #ruby-lang
wyhaines has joined #ruby-lang
seanstickle has joined #ruby-lang
darkf has joined #ruby-lang
<ezkl> Working on a gem (https://github.com/ezkl/sniffles) and can't figure out why a local install via Bundler's gemtasks works, but not if I release to Rubygems and install. Specs pass locally and on Travis. Anyone feel like lending me a fresh set of eyes?
francisfish has joined #ruby-lang
<dominikh> ezkl: define "doesn't work".
<dominikh> because it installs fine
francisfish has joined #ruby-lang
<ezkl> dominikh: Sorry. Method calls that work in both the specs and when the gem is installed locally, fail to work if installed from Rubygems. I'll post a gist.
brownies has joined #ruby-lang
dous has joined #ruby-lang
Spooner has joined #ruby-lang
burns180_ has joined #ruby-lang
<andkerosine> ezkl: Are you getting NoMethodErrors?
Sailias|work has joined #ruby-lang
<ezkl> andkerosine: I'm getting internal exceptions that should occur only if a scan of a directory glob fails to return matches. I tried to get creative with eval, so I'm guessing it is Path-related.
<andkerosine> That was my assumption.
<ezkl> andkerosine: I'm just a bit suprised that specs pass on my machine and on 1.8.7-1.9.3@Travis
<andkerosine> Then surely it's an include problem?
srbaker has joined #ruby-lang
<ezkl> andkerosine: That is what I've been assuming, but I haven't been able to identify where. Apparently, I should avoid trying my hand at meta-programming after midnight.
<andkerosine> This is gospel. : )
Joeysomo_ has joined #ruby-lang
jxie has joined #ruby-lang
darkf_ has joined #ruby-lang
<ezkl> andkerosine: I just created a fresh gemset. Cloned the repo, checked out a tag I pushed to Rubygems, ran Bundler, and `bundle exec rake install` and it is working. I'm going to try installing the same version via gem install on another clean gemset.
<andkerosine> What would it have been interacting badly with?
tomb has joined #ruby-lang
virunga has joined #ruby-lang
QaDeS has joined #ruby-lang
<ezkl> andkerosine: No idea, but I've had subtle weirdness caused by RVM and $PATH disagreements in the past. Also, much more relaxing than looking at the same hundred lines of code again.
havenn has joined #ruby-lang
<ezkl> Yeah, same issue as before with the fresh gemset.
<dominikh> ezkl: and you're sure that the gem isn't missing files that your library actually uses and has in the git repo?
<ezkl> dominikh: I've checked and everything appears intact.
<dominikh> ezkl: so, I just installed the gem, what do I do now.
<ezkl> dominikh: https://gist.github.com/5080cfa7b039ce6f82c3 - you can obviously replace Typhoeus with whatever HTTP you want. Just need to pass `Sniffles.sniff` raw HTML.
<dominikh> ezkl: returns {} here
vesan has joined #ruby-lang
minsa has joined #ruby-lang
<ezkl> dominikh: Yeah, same here. If you run `Sniffles.sniff(response.body, :wordpress)` you'll get an UnknownSniffer exception that is raised if the library is unable to find ./lib/sniffles/sniffers/cms/wordpress.rb
looopy has joined #ruby-lang
chimkan__ has joined #ruby-lang
<ezkl> dominikh: If I open the installed gem in an editor, that file is there.
<dominikh> ezkl: yeah, that obviously will not work.
<dominikh> https://github.com/ezkl/sniffles/blob/master/lib/sniffles/sniffers.rb#L11 is relative to the current working directory
<dominikh> and that's /tmp for me right now :P
<ezkl> andkerosine: :facepalm:
<ezkl> Thank you.
<ezkl> andkerosine: I knew it was something incredibly stupid.
<ezkl> er
<ezkl> dominikh
<dominikh> heh
Sailias_ has joined #ruby-lang
fayimora has joined #ruby-lang
<ezkl> dominikh: Same username on github? I'd like to give you credit in the commit.
<dominikh> ezkl: yup
gregf has joined #ruby-lang
<ezkl> dominikh: Cool. Thanks again. I can't believe I A) wrote and B) repeatedly glossed over those methods.
<dominikh> heh
<dominikh> don't worry, me neither :P
burns180 has joined #ruby-lang
fayimora_ has joined #ruby-lang
gmurphey_ has joined #ruby-lang
dous has joined #ruby-lang
chimkan has joined #ruby-lang
canton7 has joined #ruby-lang
pw_ has joined #ruby-lang
kyrylo has joined #ruby-lang
kyrylo has joined #ruby-lang
gouthamvel has joined #ruby-lang
jasonw22 has joined #ruby-lang
gouthamvel has quit ["WeeChat 0.3.0"]
burns180_ has joined #ruby-lang
mark_locklear has joined #ruby-lang
wallerdev has joined #ruby-lang
gasbakid has joined #ruby-lang
rippa has joined #ruby-lang
t4nk524 has joined #ruby-lang
<t4nk524> pastie:hi
gnufied has joined #ruby-lang
<andkerosine> So... avoid inheritance where possible.
<andkerosine> I need a Config object that's basically just a Hash, except that it writes itself to a file whenever a value changes.
<andkerosine> @config is a JSON object, and everything works fine for one-dimensional stuff.
<andkerosine> But how do I make @config.[]= work for multiple dimensions?
fayimora has joined #ruby-lang
wwalker has joined #ruby-lang
<wwalker> recommendations for a tool for 1) making CLIs 2) making a project directory with "all the right stuff" (rakefile skeleton, lib, src, doc )
<andkerosine> OptParse for CLIs.
<andkerosine> Jeweler or Bundler for gem scaffolds.
<Mon_Ouie> Alternatively, you could use Slop for option parsing
<dominikh> slop++
<wwalker> thank you. I'll look at slop and OptParse.
<wwalker> what about a tool that builds a reasonable default rakefile and project hieracrhy? My Rakefile fu (and knowledge of gem building and bundler) is weak
shyouhei_ has joined #ruby-lang
<Mon_Ouie> Depends on what you'd want as a default Rakefile
<Mon_Ouie> I sometimes don't even create one
tbuehlmann has joined #ruby-lang
<wwalker> Mon_Ouie: in the end I'd want to be able to run rake {test,gem}. I could just copy one, but I remember from differenct conferences people talking about tools that built a deafult hierarchy with some default file to start from. One was targeted at CLI tools, and I saved it in a file on my notebook, and can't find that file...
looopy has joined #ruby-lang
burns180 has joined #ruby-lang
<wwalker> gli ! (found the file :-) anyone used it?
<Mon_Ouie> I use gem build *.gemspec to build the gem, and rake :test do ruby "test/run_all.rb" end for tests, just so automated tools can run the test suite
<wwalker> Mon_Ouie: thanks
wmoxam has joined #ruby-lang
dhruvasagar has joined #ruby-lang
pemeon has joined #ruby-lang
mistym has joined #ruby-lang
burns180_ has joined #ruby-lang
jacobwg has joined #ruby-lang
gmurphey has joined #ruby-lang
jacoby has joined #ruby-lang
pw__ has joined #ruby-lang
cyri_ has joined #ruby-lang
wallerdev has joined #ruby-lang
burns180 has joined #ruby-lang
<jacoby> Can anyone give me a pointer related to class_eval?
<any-key> ruby doesn't use pointers
<jacoby> s/pointers/help/
Nisstyre has joined #ruby-lang
<jacoby> Never mind. I think I got it
ankurgel has joined #ruby-lang
<ankurgel> In a method, use of statement like: return 1 if x==2
<ankurgel> else return 0
<ankurgel> valid?
<wwalker> Am I the only ruby dev that uses ri?
<bougyman> could be
<Mon_Ouie> Nope
<ankurgel> bougyman, Mon_Ouie Why?
<bougyman> why what?
<ankurgel> was that for wwalker ?
<Mon_Ouie> Yep
<bougyman> yesh
<Mon_Ouie> And the yep was for you :p
<ankurgel> oh
<ankurgel> Mon_Ouie, Oh. :D
<Mon_Ouie> ankurgel: You need an end
<ankurgel> that is after the method return statements, right?
<Mon_Ouie> The syntax is if condition; expression; else; expression; end
<ankurgel> I was basically dubious for use of conditionals that way.
<ankurgel> return 1 if x==2
<ankurgel> else return 2
<ankurgel> valid?
<ankurgel> ofcourse, end at the end of it to end the method.
<Mon_Ouie> You can't have an else clause with a postfix if condition
chimkan has joined #ruby-lang
<wwalker> Mon_Ouie: he can't put them on separate lines if he puts the if action before the if
<wwalker> that terminates the if at the end of the line doesn't it?
<ankurgel> wwalker, Mon_Ouie Then, only correct way is : if expression; return 1; else; return 0
<ankurgel> ?
<Mon_Ouie> Well, it's never the only way
<ankurgel> wwalker, that
<ankurgel> Mon_Ouie, course. :)
<Mon_Ouie> And you still miss the return
<wwalker> ankurgel: if you want a shorter version, which seems to be what you are looking for...
<Mon_Ouie> Not to end the method that expression is part of, but to end the if expression
<wwalker> return (x==2) ? 0 : 1
<wwalker> or
<ankurgel> aah, yes, ternary!
<Mon_Ouie> return (if x == 2 then 0 else 1 end)
<wwalker> return if (x==2) 1; else 2; end
<ankurgel> got it!
<wwalker> Mon_Ouie's looks micer (and I didn't test my syntax)
<ankurgel> You guys are awesome Mon_Ouie , wwalker !
<wwalker> nicer
<ankurgel> trying that out.
<wwalker> btw, for anyone interested, gli is looking quite nice for building command line tools.
dejongge has joined #ruby-lang
carlosed has joined #ruby-lang
heppy has joined #ruby-lang
ged has joined #ruby-lang
burns180_ has joined #ruby-lang
<andkerosine> ankurgel: Ternary might be overkill for what you're doing.
<andkerosine> return 0 if x == 2
<andkerosine> And then just return 1
<andkerosine> No need for the else clause because it's implicit in this case.
<ankurgel> andkerosine, I basically was trying to make a method for palindrome
<ankurgel> on suggestion of Mon_Ouie and wwalker , framed this :
<ankurgel> return (if string.downcase.eql?(string.downcase.reverse)==true then true else false end)
<andkerosine> Determining if two strings are palindromes?
<ankurgel> if *a* string is a palindrome
<andkerosine> Ah.
<andkerosine> Um...
<ankurgel> def palindrome?(string)
<ankurgel> return (if string.downcase.eql?(string.downcase.reverse)==true then true else false end)
<ankurgel> end
<Mon_Ouie> ankurgel: You realize that then true else false is completely redundant?
<andkerosine> return string.downcase == string.downcase.reverse
<Mon_Ouie> string.downcase == string.downcase.reverse already is either true or false
<ankurgel> Mon_Ouie, please elaborate.
<Mon_Ouie> No need to use eql? either
<ankurgel> oh
<andkerosine> See, ternary is for when you want to return different values in true/false scenarios.
<ankurgel> but, ermm.. wait. thinking.
<andkerosine> But if you're after the actual boolean values, you can just return the expression.
<ankurgel> gotcha!
<andkerosine> def gimme_some_true; return 5 == 5; end
<ankurgel> yes. that was stupid code.
<andkerosine> Only a touch. : P
<ankurgel> :D
<andkerosine> Redemption: anagram method?
<ankurgel> sorry, which method is this?
<andkerosine> I was suggesting that you demonstrate your grasping of the subject by writing an anagram method.
<andkerosine> def are_anagrams(a, b); return ...; end
<ankurgel> to show all anagrams of a word?
<andkerosine> Negative.
<ankurgel> oh
<andkerosine> That ellipsis is calling you.
<Mon_Ouie> You can also drop those return
<ankurgel> what is ellipsis doing there?
<andkerosine> Yeah, never mind. : )
<andkerosine> Mon_Ouie: Left it there for clarity, but that was a bit of a lost cause. ^_^
<ankurgel> andkerosine, Mon_Ouie Corrected that to this now: def palindrome?(string)
<ankurgel> string.downcase==string.downcase.reverse
<ankurgel> end
<ankurgel> def palindrome?(string)
<ankurgel> string.downcase==string.downcase.reverse
<ankurgel> end
<ankurgel> ^
<andkerosine> Spot-on.
<ankurgel> :)
<ankurgel> thanks guys!
<ankurgel> andkerosine, Can you please elaborate on that are_anagrams thing?
<ankurgel> sounds interesting.
<andkerosine> I was asking you to write a method that returns whether or not two words are anagrams.
<andkerosine> Just to test that you /get/ the various things we've discussed here.
<ankurgel> ok, so how do I verify the combination there?
<andkerosine> That's... sort of the whole point? : )
<ankurgel> ^ this does the job?
<ankurgel> :O
morozovm has joined #ruby-lang
looopy has joined #ruby-lang
<andkerosine> No, the ellipsis is not a Ruby anagram operator, though that would be interesting...
<andkerosine> So... to check that a word is a palindrome, you simply return whether or not it is the same backwards and forwards.
<andkerosine> How do you determine if two wards are anagrams?
<andkerosine> *words
<ankurgel> Okay. Finally it made sense to me. You want me to write code at that place to check whatever we discussed here.
<andkerosine> Well, to check if two words are anagrams.
<ankurgel> hm
<andkerosine> But, in doing so, you would prove your grasp of the discussed topics.
<ankurgel> that can be done!
<andkerosine> It most certainly can.
<ankurgel> I can sort them alphabetically
<ankurgel> then,
<ankurgel> I can test for equality
<andkerosine> Huzzah!
<ankurgel> ^this is approval?
<ankurgel> :)
<andkerosine> Very much so.
<ankurgel> YESS!!
<andkerosine> It doesn't "click" like that for everybody.
<ankurgel> string.sort will work?
<andkerosine> I've seen people iterate over each word and keep a count of the letters they've seen.
<andkerosine> Ah, almost.
<andkerosine> A String is a single object, so sorting it doesn't make much sense.
<andkerosine> How to get it into sortable pieces?
<ankurgel> I have been using ruby for a while. But, not fluent in practice. Gap comes because of involvement in college stuff.
<ankurgel> but, always great to read and do it again.
<ankurgel> #ruby-lang is amazing!
<andkerosine> Being able to program, in any language, really, is just such an empowering thing.
<ankurgel> andkerosine, sorting in pieces? as in ?
<andkerosine> Well, if you're going to sort something, there obviously has to be more than one "piece". But a String like 'cba' to Ruby looks like one "piece", even though we humans see it as three pieces.
<ankurgel> oh.
<ankurgel> I can fragment a string into individual characters..
<ankurgel> push them in array.
<ankurgel> and then sort it.
<ankurgel> that way, not one 'piece'.
<andkerosine> Once again, spot-on.
<andkerosine> However, no need to do any array pushing.
<ankurgel> then?
<andkerosine> Ruby's #split will turn a string into an array of characters.
<ankurgel> yes yes yes yes
<ankurgel> I remember something about this thing.
<andkerosine> That's how it works in most languages, I think.
<ankurgel> I used it to split along spaces
<andkerosine> Mm-hmm.
<ankurgel> I mean, to break word from a sentence.
<ankurgel> s/words/words
<ankurgel> I'll have to use char regexp along with split then?
<andkerosine> Not even that much.
<andkerosine> What is it that we want to split on?
<ankurgel> "ankurgel".split(/[a-z]/) ?
<andkerosine> Hm... it works, but still overkill. : )
<ankurgel> tried it now after writing here.
<ankurgel> not working. :/
<andkerosine> ?
<ankurgel> but why is that. It seems right to me.
<ankurgel> no?
<andkerosine> I don't do much splitting, but that is how I've always assumed it would work, yes.
<andkerosine> Strange.
<ankurgel> "ankurgel".split(/./)
<ankurgel> tried this too.
<andrewvos> Can anyone work out how to reply to a specific tweet in the twitter gem? https://github.com/jnunemaker/twitter
<ankurgel> considering . as any char
<andkerosine> Huh.
<andkerosine> It appears that it splits wherever it /doesn't/ match.
<ankurgel> ermm
<andkerosine> Which strikes me as a bit counter-intuitive, but I suppose it makes sense.
<ankurgel> but?
<andkerosine> When splitting, you want to /remove/ what you're looking for.
<andrewvos> oh wait never mind I got it
<ankurgel> andkerosine, yes. oh yes.
<andkerosine> 'a1b2c3'.split(/\d/) == ['a', 'b', 'c']
<ankurgel> like breaking space to seperate word from lines.
<andkerosine> Mm-hmm.
<andkerosine> If, however, we want to break a string into characters indiscriminately, we want to split everything, so we pass in nothing.
<andkerosine> It almost sounds like philosophizing. : )
<ankurgel> "ankurgel".split(/[^a-z]/)
<ankurgel> => ["ankurgel"]
<andkerosine> 'ankurgel'.split(//)
<ankurgel> this makes sense
<ankurgel> eh?
<ankurgel> this?
<ankurgel> wow
<andkerosine> An empty Regexp or an empty String will suffice.
<ankurgel> but, how?
<ankurgel> This was W.O.W
<andkerosine> It means "split wherever you see this", and because it will see an empty string between every character, it works.
<Defusal> hmm, i've been writing too much low level code lately
<ankurgel> andkerosine, fantastic!
<andkerosine> It's a bit of a mindfuck, but it makes perfect sense when you think about it.
<ankurgel> for word?
<andkerosine> Hm?
<ankurgel> and it feels good when it finally works!
<andkerosine> Every time.
<Defusal> whats the best way to mixin nested modules and classes from a module into another module?
<Mon_Ouie> each_char
<andkerosine> Excessive for the task at hand, maybe.
<andkerosine> Defusal: The :: operator?
<Defusal> andkerosine, i didn't ask how to reference classes or modules in another module
<ankurgel> andkerosine, Mon_Ouie Please to explain what's going on here:
<ankurgel> 1.9.2p290 :039 > "hello world".gsub(/\w/){|x| x.upcase}
<ankurgel> => "HELLO WORLD"
<ankurgel> 1.9.2p290 :040 > "hello world".gsub(/\b./){|x| x.upcase}
<ankurgel> => "Hello World"
<ankurgel> 1.9.2p290 :041 > "hello world".gsub(/b/){|x| x.upcase}
<ankurgel> => "hello world"
burns180 has joined #ruby-lang
<Mon_Ouie> What do you not understand exactly?
<andkerosine> ankurgel: Are you familiar with the \b and \w flags?
<ankurgel> no
<andkerosine> Ah.
<ankurgel> what sort of flags are they?
<ankurgel> and what does /b./ exactly denote here?
<Mon_Ouie> \b isn't the same as b
<andkerosine> /b./ means find the letter "b" followed by anything.
<ankurgel> yes. regexp way.
<ankurgel> \b is escaped,
<ankurgel> so it must denote something
<Mon_Ouie> \b matches at points that mark the boundaries of a word
<Defusal> ohh i see
<Defusal> i used a hack when i needed to do it last year
<ankurgel> points to start boundary or end boundary?
<Defusal> because i couldn't come up with a better solution at the time
<Defusal> ended up defining const_missing in the class
<Defusal> i guess thats not the of the world, if theres no better way
<Mon_Ouie> It's a 0-width match, though, so matching the next character is needed if you want to replace something
<ankurgel> /\b./ so it points to first char of word
<andkerosine> Spot-ons: 3. : P
<ankurgel> and /\w/ points entire word instead, so all uppercase.
<andkerosine> Not quite.
Bwild has joined #ruby-lang
<ankurgel> and /\b/ points to nothing except boundary
<ankurgel> andkerosine, why?
<ankurgel> it extracts whole word, no?
<andkerosine> \w is a flag to match "word characters".
<ankurgel> or each char of word?
<andkerosine> Things like letters and numbers.
<ankurgel> i see..
<ankurgel> making some sense.
<andkerosine> /\w/ =~ '.,%^'
<andkerosine> # => nil
<andkerosine> Because it didn't find any "word-like" characters.
<Mon_Ouie> ankurgel: \b actually matches both end and begin of the word
<Defusal> ah right, const_missing is probably the best way anyway, since even if i did add the first modules constants to the second module, i would have to remove and recreate the reference whenever the first module is reloaded
<andkerosine> So /.\b/ to capitalize the last character of a word.
<ankurgel> Mon_Ouie, but it can't at a single point of time.
<ankurgel> oh
<andkerosine> Well, to match, not necessarily capitalize.
<ankurgel> So, it's like </ and />
<Defusal> i just get the feeling that const_missing is not very good for performance
<andkerosine> Depends on how often you're going to make Ruby traverse, of course.
<Mon_Ouie> But since the character after the end is always a non-word character, capitalizing it never does anything
<ankurgel> andkerosine, NICE. that example was good.
<ankurgel> reading it again.
<Mon_Ouie> Which is why it can be ignored in your gsub expression
<andkerosine> =~ is an excellent way to get your Regexp bearings.
<andkerosine> String =~ Regexp, or Regexp =~ String.
<andkerosine> For testing all of the options and whatnot.
<ankurgel> it is used to test against a regexp right?
<Defusal> andkerosine, yup, well whenever referring to the models that are mixed into a module
<ankurgel> .match can also be used , I think.
<yxhuvud> defusal: usually, it is not evaluated many times, since contants tend to be, well, constant
<andkerosine> Indeed.
<andkerosine> #match will provide much more thorough data.
<Defusal> the point is to keep the models out of the top level namespace
<andkerosine> =~ simply returns the index at which the first match was found.
<ankurgel> so, usage wise =~ is more handy!
<Defusal> so i am reading the model code manually and evaluting it with a new Module instances binding
<andkerosine> ankurgel: For quick tests, definitely.
<ankurgel> cool!
<andkerosine> For more complex patterns, though, you may want to use #match to see exactly what's being captured.
<Defusal> then const_missing will look through the modules when it needs a model constant
achiu has joined #ruby-lang
<ankurgel> andkerosine, [,`!"`] are counted as non-word characters?
<andkerosine> Mm-hmm.
<andkerosine> Any punctuation.
<ankurgel> testing.
<andkerosine> I believe \w is just a shortcut for [A-Za-z0-9]
francisfish has joined #ruby-lang
<Mon_Ouie> Depends on Ruby version
<andkerosine> Mm-hmm.
<ged> andkerosine: And '_'.
<ankurgel> andkerosine, " is still counted in it I think.
<Mon_Ouie> In 1.8, it can match UTF-8 word characters with appropriate regexp flags
<ankurgel> how do I test it ?
<andkerosine> /\w/ =~ '"' == nil
<Mon_Ouie> In 1.9, it's what you said + _, as ged said
<ankurgel> probably in []
<andrewvos> MWUAHAHAHAHAHAHAHA https://twitter.com/#!/youreyoureyoure
<andkerosine> andrewvos: NLP?
<andkerosine> Or... not yours?
<andrewvos> andkerosine: search("you're a")
<ankurgel> /\w/=~'"' not working
<ankurgel> fantastic, it worked: /\w/=~'["]'
<Mon_Ouie> Your a looks quite great!
<andrewvos> haha
<andkerosine> ankurgel: The first one worked on my end.
<andrewvos> Damnit I got to leave in 20 minutes
<ankurgel> andkerosine, on 1.9.2?
<andrewvos> I wanted to put it on heroku but I guess a cron job could work
<andkerosine> 1.9.3
<andkerosine> Heroku + cron.
<andkerosine> ankurgel: Works on 1.8.7, too, so I think you may've mistyped?
tomzx has joined #ruby-lang
<ankurgel> andkerosine, must have.
<ankurgel> andkerosine, I am trying one thing here now. Coming back with problem in it, soon. :D
<andkerosine> Problems beget solutions. : )
<andrewvos> <3 heroku
Z33K|Lux has joined #ruby-lang
<andrewvos> Please don't put that on ShitRubyistsSay ^
<andkerosine> s/Shit/BeautifullyTrueThings
<andrewvos> haha
<andrewvos> Ok cronjob setup
<andrewvos> Damn the heroku scheduler makes me happy
<ankurgel> andkerosine, YEAH. I was trying to improve that palindrome thing. Such that a string like: "Madam, I'm Adam!" is treated as palindrome too.
<andkerosine> Nice!
<ankurgel> that is it will disregard all spaces, and punctuations etc.
<andkerosine> Mm-hmm.
<ankurgel> first, I did.
<ankurgel> string.downcase!
<ankurgel> then,
<ankurgel> string.gsub(/\W/){|m|}
<ankurgel> result:
<ankurgel> madamimadam
<andkerosine> Ah, negative.
<andkerosine> Oh, it did work?
<ankurgel> yes, it did.
<andkerosine> Mm-hmm.
<andkerosine> But you don't need the block syntax for that use case.
<ankurgel> Why, negative? Where did I do wrong?
<andkerosine> string.gsub(/\W/, '')
<andkerosine> Replace non-word characters with nothing.
<ankurgel> I can simply substitute by this way also?
<ankurgel> cool!
<andkerosine> Well, yeah, but it's slightly less efficient and also just the "not right" way to do it, so to speak.
<ankurgel> noting it down.
<andkerosine> The block syntax is for manipulating captures.
<andkerosine> You're not capturing anything (with parentheses), so |m| is blank, thus the intended effect.
minsa has joined #ruby-lang
<ankurgel> :) Ok
<andkerosine> Just a heads-up.
<ankurgel> was really needed. :)
<andkerosine> It seems like something that would have the potential to trip you up down the road, so I figured I'd point it out.
<ankurgel> wait..
<ankurgel> I didnt' get that point completely.
havenn has joined #ruby-lang
<ankurgel> I mean,
<ankurgel> should I refrain from using empty blocks?
<andkerosine> Oh, yes.
<andrewvos> andkerosine: yeahhh
<andrewvos> definitley
<andrewvos> err I mean ankurgel
<andkerosine> Heh.
<ankurgel> andkerosine, andrewvos But, why? o.O
<andkerosine> I mean, think about it, what purpose could an empty block possibly serve? : )
<andrewvos> andkerosine: Cause it just looks stupid?
<andkerosine> It makes Ruby do a little extra work, and for no real reason.
<ankurgel> non-required iteration. gotcha.
<andkerosine> #gsub can behave several different ways, which is common in Ruby, but you want to make sure you're using the right format for the task.
<ankurgel> hm
<andkerosine> ankurgel: Nailed it.
<andkerosine> #gsub's block syntax is amazing, but you should only use it when you need it.
<ankurgel> andkerosine, what if I wanted the space to remain there and every other punctuation to be removed?
<andkerosine> Because you just want to /remove/ certain characters, the #gsub(old, new) format suffices.
<ankurgel> Certainly modification of regexp must be required.
<andkerosine> Match on /[\w ]/
<ankurgel> andkerosine, yes. :) and that's even more handy!
<andkerosine> Essentially, you want word characters and spaces, so rather than jumping through hoops, just tell the parser you want word characters and spaces. : D
<ankurgel> can I chain method like: string.downcase!.gsub! .. ?
<andkerosine> Certainly.
<andkerosine> No need for the !, though.
<ankurgel> But, I want the changes to made it in string itself.
<ankurgel> first downcase and then substitution.
<ankurgel> so. method chaining will work that way ? (by use of !) ?
burns180_ has joined #ruby-lang
<andkerosine> Hm, this is sort of tricky to describe "cleanly", but basically, if you're chaining, there's no need to modify the object in place, because you're still passing along the modified value within the chain.
<ankurgel> 1.9.2p290 :064 > string.downcase.gsub!(/\W/,'')
<ankurgel> => "madamimadam"
<ankurgel> 1.9.2p290 :065 > string
<ankurgel> => "Madam, I'm Adam!"
<ankurgel> :(
<ankurgel> Dont' want to use string = string.downcase.gsubs!...
<ankurgel> andkerosine, ^
<andkerosine> Huh.
<andkerosine> I don't know where my misconception came from. : /
<andkerosine> My apologies for misleading.
<andkerosine> ! all the way, although I still don't quite understand why that is.
<nofxx> Hehe.. is only here that apache.org is off ?
<ankurgel> andkerosine, ?
<ankurgel> trying
<ankurgel> worked now.
<ankurgel> but, again, why?
<nofxx> maybe it's because it's running.... apache! =D with java on top
<bougyman> CRAPache
<andkerosine> Alas, I don't know.
<nofxx> bougyman, heheh.... need an alternative to 'ab'
<andkerosine> My understanding was that string.downcase.gsub! would work because downcase is passing the string object itself to gsub!, but apparently not...
<bougyman> nofxx: siege
<shevy> bougyman: counter-siege!
<andkerosine> Well, yeah, it makes sense.
<andkerosine> #downcase just returns a modified string, so the object isn't passed to #gsub!.
<andkerosine> In short, yes, ! in chains to modify in-place.
<nofxx> cool! thanks bougyman shevy , found
<andkerosine> And, again, sorry for taking us down this winding road to confusion.
<ankurgel> downcase returns the modified string, yes.
<ankurgel> but that is passed to gsub!
<ankurgel> which actually modifies string
<ankurgel> should be like this only.
<andkerosine> Well, no.
<andkerosine> #gsub! is just receiving /a/ string object, in that case, not /the/ string object.
<ankurgel> andkerosine, It's perfectly cool, man. :)
<ankurgel> Ruby is fascinating .
<andkerosine> Absolutely.
chimkan__ has joined #ruby-lang
<andkerosine> It's such a treat to program in if you're coming from most other languages.
<ankurgel> andkerosine, so, here my snippet actually looks like,
<ankurgel> def palindrome?(string)
<ankurgel> string.downcase!.gsub!(/\W/,'')
<ankurgel> string==string.reverse
<ankurgel> end
<ankurgel> puts "Enter string to check for palindrome: "
<ankurgel> str=gets.chomp
<ankurgel> puts palindrome?(str) ? "true" : "false"
<ankurgel> #courtesy YOU andkerosine
<andkerosine> Athangya.
<andkerosine> Though... no need for that ternary, remember?
<andkerosine> Your palindrome? method returns a boolean, just use it. : D
<ankurgel> using it to show result
<andkerosine> Take it off. : )
<Mon_Ouie> Because true.to_s is "true", and puts will call to_s on its argument
<ankurgel> text result.
<ankurgel> okay. :)
<andkerosine> #puts will implicitly try to make a string out of anything you give it.
Bwild has joined #ruby-lang
<andkerosine> ankurgel: https://gist.github.com/1967725
<andkerosine> The benefit of modifying in-place. : )
<andkerosine> On the right side of ==, string is in its modified form.
gjaldon has joined #ruby-lang
chimkan__ has joined #ruby-lang
<ankurgel> wow, awesome!
<ankurgel> it will take modified one at right side?
<ankurgel> what the hell, everything was working a minute ago.
<ankurgel> now getting:
<ankurgel> `palindrome?': undefined method `gsub!' for nil:NilClass (NoMethodError)
<ankurgel> from 3.rb:5:in `<main>'
Dreamer3 has joined #ruby-lang
minsa has joined #ruby-lang
<ankurgel> andkerosine, ^^
Dreamer3 has joined #ruby-lang
<andkerosine> ankurgel: Show me code?
<andkerosine> Somewhere you're accidentally throwing your object away.
chimkan__ has joined #ruby-lang
<ankurgel> Here's the one you gist-ed:
<ankurgel> def palindrome?(string)
<ankurgel> string.downcase!.gsub!(/\W/, '').reverse == string
<ankurgel> end
<ankurgel> puts "Enter string: "; str=gets.chomp
<ankurgel> palindrome?(str)
havenn has joined #ruby-lang
Dreamer3 has joined #ruby-lang
<ankurgel> Here's earlier one:
<ankurgel> def palindrome?(string)
<ankurgel> string.downcase!.gsub!(/\W/,'')
<ankurgel> string==string.reverse
<ankurgel> end
<ankurgel> puts "Enter string to check for palindrome: "
<ankurgel> str=gets.chomp
<ankurgel> puts palindrome?(str) ? "true" : "false"
<Mon_Ouie> Use pastie or gist to paste code
gix has joined #ruby-lang
fayimora has joined #ruby-lang
<ankurgel> Mon_Ouie, Okay. :) Sorry. Will do that from now.
<jorgenpt> ankurgel: The ! methods on string return nil if there's no change to the object.
<nofxx> Dammit, I'm mad!
<jorgenpt> ankurgel: When chaining like that, use the non-! methods. :-)
<nofxx> only palindrome phrase I remember in english*
<jorgenpt> ankurgel: So string.downcase.gsub
<Mon_Ouie> Plus modifying arguments is bad form
<jorgenpt> ankurgel: (They also modify the string in question, which isn't cool for arguments)
<ankurgel> jorgenpt, hey, but it was working a minute ago, all fine.
<nofxx> ankurgel, good test case too, the single quote will break your regex heh
<jorgenpt> ankurgel: It'll work if you type in something that has capitalization and non-word characters.
<andkerosine> jorgenpt: Well, both the reversed form and the original need to be downcased and replaced, thus the ! methods.
<ankurgel> it solved it though :)
<andkerosine> ankurgel: 'ABC'.downcase! == 'abc'
<andkerosine> 'abc'.downcase! == nil
<jorgenpt> andkerosine: Fair enough
<andkerosine> Which I guess makes sense, but I think it's one of the few places Ruby violates the principle of least surprise.
<ankurgel> andkerosine, jorgenpt Aah ok.
<ankurgel> 'abc'.downcase! is appending nothing to further chain?
<jorgenpt> ankurgel: cleaned = string.downcase.gsub(/\W/, ''); cleaned == cleaned.reverse
<andkerosine> Which is what he had.
<jorgenpt> Orly.
<andkerosine> I was just trying to show Ruby's power by condensing it to one line, but that ended badly. : )
<ankurgel> :D
<nofxx> andkerosine, ruby often surprises me too, bringing some sanity and happiness
<jorgenpt> andkerosine: haha ;-)
<ankurgel> I still would like it in one line!
<jorgenpt> You can use tap if you really really want to :-p
<ankurgel> .tap ? I don't remember it now.
<jorgenpt> string.tap {|s| s.downcase! }.gsub!(/\W/, '')
<nofxx> andkerosine, to a gray, vogon world
<jorgenpt> foo.tap calls the block with foo then returns foo, ignoring the blocks return value
<ankurgel> doesn't that imply string=string.downcase.gsub(/\W/,'') ?
<jorgenpt> I'm not sure what you're saying :-)
<andkerosine> He's exploring the utility to ! methods to avoid having to re-declare a variable.
<ankurgel> I am trying to understand that explanation again.
<jorgenpt> My code doesn't require string = ..., it modifies it in-place
<ankurgel> oh
<ankurgel> gotcha
<andkerosine> #tap is confusing at first.
<ankurgel> # calls the block with foo then "returns foo", ignoring the blocks "return value"
<ankurgel> it is still confusing.
<ankurgel> but, it is looking good. :D
glupo has joined #ruby-lang
<jorgenpt> Is tap a 1.9 thing?
<glupo> heloo
<ankurgel> andkerosine, ^
<andkerosine> jorgenpt: Nope.
<jorgenpt> Hm. It's not working on codepad.org
<andkerosine> jorgenpt: Y U NO RVM?
<glupo> having some troubles with delayed job
<glupo> failed with TypeError: can't convert String into Hash
<jorgenpt> I do, I was just being lazy :$
<jorgenpt> undefined method `tap' for "L-o'l":String (NoMethodError)
<glupo> can any1 help?
<ankurgel> andkerosine, :D
<glupo> =)
<andkerosine> 1.8.7 :001 > 'x'.tap
<andkerosine> LocalJumpError: no block given
<jorgenpt> Yeah
<jorgenpt> I guess codepad.org disables it for some reason?
<andkerosine> Seems to be the case.
<andkerosine> glupo: Code. : )
<glupo> my_sender[room].delay.send("Bot", message)
<jorgenpt> ankurgel: http://codepad.org/Ax0pbWK6
<jorgenpt> ankurgel: Ignore the 'class Object' stuff.
<ankurgel> andkerosine, jorgenpt , you guys remain around here? on #ruby-lang ?
<jorgenpt> I'm here 24/7, I just very rarely say anything
<ankurgel> cool. But, notice when anyone 'mentions' you here?
skipper has joined #ruby-lang
<ankurgel> You guys are great guidance around here.
<andkerosine> ankurgel: I jump in whenever I have a question, and then stay for a while. : )
<ankurgel> seriously learnt some kickass thing by you andkerosine and others. :)
<andkerosine> Hopefully you've only just begun. : D
<ankurgel> andkerosine, erm. Same with me. but.. :|
looopy has joined #ruby-lang
jkyle has joined #ruby-lang
<ankurgel> andkerosine, begun many months back. Coding basic programs only though.
<andkerosine> We crawl before we run.
<jorgenpt> ankurgel: Usually respond, yeah. There's usually someone in here who can answer, though, and probably knows more than me :-)
<ankurgel> as I said, the gap in practice is the convict.
<andkerosine> Try to find ways to use it every day, little by little.
<ankurgel> definitely.
<andkerosine> Programming is such a broad spectrum that you really can find /some/ way to use code to help you do just about anything, however small.
<andkerosine> Monitor your inbox. : )
burns180 has joined #ruby-lang
<ankurgel> programming is not the problem. I kinda use more of C++ than anything. But, college tends to remain us busy in some crap subjects.
<ankurgel> Ruby is benevolent though. Purely fascinating.
<andkerosine> ankurgel: Nothing wrong with it being a hobby.
mqt has joined #ruby-lang
<andkerosine> But it kind of grows on you, Ruby in particular, the more you use it.
adgar has joined #ruby-lang
spectra has joined #ruby-lang
glupo has quit [#ruby-lang]
<andkerosine> If all you have is a hammer, everything's a nail, but Ruby makes your hammer very shiny.
<ankurgel> now, that is philosophical. :D
<ankurgel> But, true. :)
yellow5 has joined #ruby-lang
<andkerosine> Brain food. : )
<ankurgel> .all? sees it collectively?
<ankurgel> I mean, an array back as a single entity?
<andkerosine> Well, yes.
<nofxx> More like swiss army knives! same color too
<andkerosine> Goes through every array element and only returns true if all elements are "true".
<andkerosine> [1, 5, 'bacon', 10, nil].all? == false because of the nil.
blowmage has joined #ruby-lang
<ankurgel> oh.
<ankurgel> but, why check that?
<andkerosine> Hm?
<ankurgel> there must be no nil there.
<andkerosine> Right, no, that was just a demonstration of how it's used.
<ankurgel> :) okay
<andkerosine> In the case of are_anagrams, I'm using #all? on the map to ensure that every element is equal to the first, which will only be true if all the passed arguments are anagrams of each other.
<andkerosine> Note that #map would not have been sufficient.
<ankurgel> I'll look it again. In middle of some other snippet. :)
<andkerosine> Right on. : )
<ankurgel> andkerosine, check this please: https://gist.github.com/1967974
<ankurgel> though this works.
<ankurgel> it's the old one I made sometime back. Pickaxe helped in this, I think.
<andkerosine> Looking for the more Ruby way to do it?
<ankurgel> Don't remember...
<ankurgel> andkerosine, confused in one thing there, first.
<andkerosine> Which is?
<ankurgel> why c[a_word] assumes that hash's other other value would be 0 at first place?
havenn has joined #ruby-lang
<ankurgel> We didnt' specify it anywhere explicitly, did we?
<andkerosine> Well, that's what passing a parameter to Hash.new does.
<ankurgel> predefined?
<andkerosine> It's a placeholder for any key that doesn't exist.
<ankurgel> not garbage value? if left parameter is decided.
<andkerosine> Mm-hmm.
<andkerosine> Useful, because rather than checking if the key exists before incrementing it, you just start it at 0 and you know you're good.
<ankurgel> that's where I'm confused. "you just start it at 0" <-
<ankurgel> OH
<ankurgel> gotcha ! :)
<ankurgel> thanks
<andkerosine> : )
<ankurgel> If I do str=string
<ankurgel> and do changes to str
<ankurgel> string gets effected by same.
<ankurgel> How do I seperate them?
<ankurgel> there was something.
<ankurgel> separated as in, change on one doesn't inflict change on another.
<shevy> ankurgel .dup on string
<andkerosine> str = string.dup
<ankurgel> okay
<ankurgel> dup denotes ?
<andkerosine> There are pretty much an infinite amount of ways to do it (as long as you change the object in some way, it will pass by value), but #dup is the cleanest and makes the most semantic sense.
<andkerosine> Hm... we'd have to get into passing by value and passing by reference. Maybe you know them from C++?
<ankurgel> yes.
<ankurgel> so, earlier analogy followed passing by reference.
<ankurgel> but dup forces copy of object.
burns180_ has joined #ruby-lang
<ankurgel> and thus pass by value?
<andkerosine> Precisely.
<andkerosine> As soon as you do anything to the right side, it becomes a new object, and thus only the value is passed.
<ankurgel> Oh. so, basically dup doesn't chagne anything, only returns back the object.
<ankurgel> but that object is now treated as another object
<ankurgel> which is copied into lvalue
<andkerosine> Specifically /not/ the object.
<ankurgel> and thus, seperated out.
<andkerosine> Just the value.
<ankurgel> ok :)
<ankurgel> see this, str=str.downcase.gsub(/\W/,'')split
<ankurgel> doing same, downcasing, then removing every space, punctuation etc and then splitting.
<ankurgel> but, I want here to keep space intact,
<ankurgel> so that it can split from spaces in last method chain
<andkerosine> So, rather than splitting on non-word characters, you'll have to use a character class.
<ankurgel> can't use ^/\W/ as it will denote at "starting of line" and not 'NOT'
<andkerosine> Right.
<andkerosine> ^ is start of line unless it's inside a character class, [], which then takes on the NOT meaning.
<ankurgel> yes
<andkerosine> [^a-z] will match anything but lowercase letters.
m3nd3s has joined #ruby-lang
<andkerosine> Ruby's Regexp engine supports a /lot/ of character classes.
<ankurgel> hm
<ankurgel> str.downcase.gsub([^a-z ]*).split ?
<ankurgel> added space in there, because have to exclude that too.
<ankurgel> space will make split possible later.
havenn has joined #ruby-lang
<andkerosine> No need for the *?
<ankurgel> but, multiple characters?
<ankurgel> for a word formation
<ankurgel> or a sentence formation to be precise excluding punctuation marks
<andkerosine> It will find all of them regardless.
<andkerosine> #gsub will go and go until the string no longer contains any of the characters you want to remove.
<ankurgel> got it. ;)
<andkerosine> Of course, you're not trying to remove lowercase letters.
<ankurgel> 1.9.2p290 :026 > str.downcase.gsub([^a-z ],'')
<ankurgel> SyntaxError: (irb):26: syntax error, unexpected '^', expecting ']'
<ankurgel> str.downcase.gsub([^a-z ],'')
<ankurgel> ^
<ankurgel> (irb):26: syntax error, unexpected ']', expecting $end
<ankurgel> str.downcase.gsub([^a-z ],'')
<ankurgel> ^
<ankurgel> from /home/ruby/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
<ankurgel> sorry for pasting it right here, again.
<andkerosine> Missing // around your Regexp. : )
<shevy> well where is the //
<andkerosine> (It's almost a competition between us now.)
<ankurgel> oh
<ankurgel> lolwut?
<andkerosine> Last time shevy beat me to #dup.
<ankurgel> aah :D haha
<shevy> I am no longer that young anymore, so you young ones beat me on that
<andkerosine> Youth, like all things, is a relative notion, my friend.
<erikh> wow, you guys are almost as busy as python today
<ankurgel> worked! Thanks shevy andkerosine again :)
<erikh> #python that is
<shevy> I see you are also getting older andkerosine :-)
gasbakid has joined #ruby-lang
<ankurgel> erikh, #python doesn't remain engage either 24/7 I think.
pw_ has joined #ruby-lang
<erikh> it's pretty busy
<erikh> typically a lot busier than here.
<andkerosine> It gets the math crowd, I imagine.
<andkerosine> And, alas, for good reason.
<erikh> nah, there's #ruby and #ruby-lang which probably dilute things a bit
<erikh> and #ror which, for better or worse, is a lot of where ruby users want to be
jkyle has joined #ruby-lang
<andkerosine> Certainly for worse.
<ankurgel> erikh, What's there in #ruby ? Never been there.
<erikh> it doesn't matter much, it was more of a "wow, this channel is busy today"
<andkerosine> I don't understand how people can hold the mindset that learning a framework before the language it's built on makes any sense.
seanstickle has joined #ruby-lang
<erikh> ankurgel: just a personal spat between the ops here and the ops there. disregard it
<ankurgel> andkerosine, I tried RoR, gave up after a sample application.
<ankurgel> Will get back to it after proficiency in Ruby first.
<erikh> andkerosine: I think it speaks volumes about ruby's ability to communicate without having any underlying knowledge
<andkerosine> It is not a pleasant introduction, I don't think.
<erikh> that's good language design
<andkerosine> Good point.
<erikh> that said, I agree with you otherwise.
<andkerosine> It leads to so much more confusion than is necessary.
<ankurgel> wait, my comment in context here ^^?
<andkerosine> ankurgel: Have you looked at Sinatra?
<ankurgel> no
<andkerosine> Do that. : )
<andkerosine> I shit you not, Heroku + Sinatra == two-minute web app.
<erikh> think you could figure out what that does without knowing ruby?
<andkerosine> Certainly.
<ankurgel> I was using scaffolding technique while using it. It was simple as well.
<erikh> fwiw, rails 2 was a lot better in this regard, but rails 3 is more of a "big boy" web framework
<andkerosine> Big deterrent for beginners, I think.
<andkerosine> "Oh, you want web app? Well, here, take these 300 files first."
<erikh> right -- rails 2 for the most part was a lot simpler.
<erikh> I mean, I get brain tired when I think about what java web-types have to deal with
<erikh> android was enough kthx
<andkerosine> Mm-hmm. It's by no means inferior, and convention is certainly better than mountains of configuration.
<shevy> hmm
<andkerosine> It just feels "constricting", in a sense.
<erikh> anyhow I need to port my awesome cinch bot to elasticsearch
<andkerosine> Well, no, it /is/ constricting, but that's part of its charm, I guess.
<pw_> andkerosine: should'nt it be I shit you not, Heroku + Sinatra = two-minute web app.
<pw_> :-)
<andkerosine> pw_: This is a programming channel, good sir.
<ankurgel> :D
<pw_> andkerosine: exactly
<dominikh> Heroku + Cinch == two-minute IRC bot.
<andkerosine> ^ You're sexy.
<andkerosine> ...
<andkerosine> pw_: We have a different definition of equality.
<pw_> andkerosine: no :-) we have a different definition of two-minute web app
<andkerosine> I meant... programmers have a different definition of equality.
<andkerosine> Heroku + Sinatra = two-minute web app would be assigning to the variable, Heroku + Sinatra, which... doesn't make any sense.
<andkerosine> This is a strange point of contention...
<pw_> Heroku + Sinatra == two-minute web app would be testing if it is a two minute web app
<andkerosine> And would return true. ^_^
<pw_> put = would assign two-minute web app to heroku + sinatra
<andkerosine> (I see where you're coming from...)
<pw_> andkerosine: where is that?
wmoxam has joined #ruby-lang
<dominikh> = is wrong from the standpoint of both programming and mathematics...
burns180 has joined #ruby-lang
<pw_> I shall shut up now and go hide in a corner
<andkerosine> It's pure semantics, of course, so no hard feelings.
ryanf has joined #ruby-lang
chimkan_ has joined #ruby-lang
<andkerosine> ankurgel: https://gist.github.com/1968177
<andkerosine> More brain food. : )
<andkerosine> You pretty much never need an explicit "for" loop in Ruby.
<ankurgel> andkerosine, checking
<ankurgel> :)
wyhaines has joined #ruby-lang
<ankurgel> andkerosine, that final thing I was trying to make: https://gist.github.com/1968188 :)
<ankurgel> andkerosine, I replaced for loop with .each iterator instead. Better?
davidw has joined #ruby-lang
<andkerosine> Mm-hmm.
<andkerosine> Hash[] and #zip are really powerful, mind you, so do look into them, but that's definitely more idiomatic Ruby.
<andkerosine> On that note, set your editor up to intend 2 spaces rather than 8. : )
<andkerosine> *indent
<ankurgel> will look it very shortly. heard #zip for first time.
<ankurgel> :set indent = 2 ?
<tobiasvl> vim?
<ankurgel> yes
<tobiasvl> set autoindent " auto-indent new lines
<tobiasvl> set smartindent " auto-indent things in braces
<tobiasvl> set smarttab
<tobiasvl> set expandtab " away with those pesky tabs
<tobiasvl> set shiftwidth=4 " number of spaces per indent level
<tobiasvl> set softtabstop=4 " number of spaces to e.g. delete with backspace
<erikh> ahhhh
<tobiasvl> :)
<tobiasvl> plus:
<tobiasvl> set backspace=2 " make backspace sane (set backspace=eol,start,indent ?)
<erikh> use a pastebin next time :P
<ankurgel> tobiasvl, :) Woahaa wohaa woahaa
* andkerosine uses Sublime Text.
* andkerosine hides.
<ankurgel> tobiasvl, after I end a function or something and write 'end' in next line, it doesn't get written at the fencing of function-start.
<ankurgel> what to do about that?
<ankurgel> andkerosine, :O Heard it's popular. Didn't give it a shot yet. :P
lsegal has joined #ruby-lang
<andkerosine> Insane how featureful and yet fast it is.
<andkerosine> Also Vintage plugin for moving around like vim.
<ankurgel> s/popular/new&popular
<ankurgel> andkerosine, there is no proper doc of it!
<andkerosine> #gsub('popular') { |match| 'new&' + match }
<ankurgel> and whatever is available goes over my head.
<andkerosine> ^ A case for block-syntax gsub.
<ankurgel> andkerosine, YOU SIR ARE GREAT. *bows*
<tobiasvl> erikh: as long as irssi lets me paste it without pressing ctrl+k i feel it's within the limits ;)
<andkerosine> Ctrl-Alt-G puts a Gist URL in my clipboard. : )
<andkerosine> So glorious.
<erikh> tobiasvl: there are limits specified in the topic
<tobiasvl> erikh: oops :) i'd better pay more attention then
<erikh> well, it's your ass if one of hte ops flies in and sees that :)
<ankurgel> :D
<dominikh> and fyi, even if there wouldn't be anything in the topic, 3 or 5 lines is the default in any sane channel
<andkerosine> "OPing; it gives you wiiings."
<ankurgel> New brand line ^
<ankurgel> andkerosine, Gist plugin is pretty awesome for vim.
<ankurgel> Just :gist and pufff
<andkerosine> Nice.
<andkerosine> Ctrl-[ feels pretty cool, too.
<andkerosine> But Sublime just "feels" so nice.
io_syl has joined #ruby-lang
<ankurgel> for Esc, yes. Handy.
<ankurgel> I will resist the temptation.
<andkerosine> Very, particularly with my standby key, like, a millimeter away.
tekin has joined #ruby-lang
slyphon has joined #ruby-lang
voker57 has joined #ruby-lang
voker57 has joined #ruby-lang
eggman2001 has joined #ruby-lang
gasbakid has joined #ruby-lang
f13o has joined #ruby-lang
burns180_ has joined #ruby-lang
rolfb has joined #ruby-lang
Bwild has joined #ruby-lang
malev has joined #ruby-lang
<ankurgel> andkerosine, yours https://gist.github.com/1967920 is giving me false.
<ankurgel> oops wait
<ankurgel> True.
minsa has joined #ruby-lang
S1kx has joined #ruby-lang
S1kx has joined #ruby-lang
m3nd3s has joined #ruby-lang
wmoxam_ has joined #ruby-lang
fayimora has joined #ruby-lang
uniqanomaly has joined #ruby-lang
erpuds has joined #ruby-lang
burns180 has joined #ruby-lang
S2kx has joined #ruby-lang
<andkerosine> ankurgel: Heh, what was the bug that made it give false?
<ankurgel> andkerosine, BOOM. ping
<ankurgel> nothign, I chose one string wrong.
<andkerosine> Mm, thought that might be it.
<ankurgel> I need your help in another program.
<andkerosine> By all means.
<ankurgel> but, this question is kinda my homework (being honest).
<andkerosine> All the more laudable.
* andkerosine switches to guide mode.
<ankurgel> :)
<ankurgel> okay, wait a sec
<ankurgel> anagrams question.
<ankurgel> # input: ['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams',
<ankurgel> 'scream']
<ankurgel> # => output: [["cars", "racs", "scar"], ["four"], ["for"],
<ankurgel> ["potatoes"], ["creams", "scream"]]
<ankurgel> groups anagrams.
<ankurgel> order doesn't matter in output.
<andkerosine> Ooh, very nice.
<ankurgel> what I made till now:
<ankurgel> gisting, wait
<andkerosine> sleep until #ruby-lang.messages.last.author == 'ankurgel
<ankurgel> andkerosine, :D
<ankurgel> It is the first time I'm actually participating in this much long discussion at #ruby-lang
<ankurgel> always used to remain idle
<andkerosine> Here be learning treasures.
<andkerosine> Okay, well, you see what's happening, right?
<ankurgel> yes,
<ankurgel> I sorted, joined back.
<ankurgel> so, I have the structure made up.
<ankurgel> few things left at end.
<ankurgel> but they are bamboozling
<ankurgel> that is what paused me.
<eggman2001> is there a way for me to do text + variable to reference another variable?
<andkerosine> Ack, I don't want to show you my solution just yet, but the solution likely requires a few things you might not know...
<andkerosine> eggman2001: Symbols.
<ankurgel> hm
macmartine has joined #ruby-lang
<andkerosine> Otherwise you unnecessarily introduce #eval-ish methods.
<eggman2001> for example, var1 = 123; a = 1; so var + a in some way
<andkerosine> :var1 = 123
<andkerosine> :"var#{a}"
<ankurgel> andkerosine, should I create an hash up there as well?
Bwild has joined #ruby-lang
<ankurgel> relating sorted element and original element.
<eggman2001> andkerosine: that just returns a string
<eggman2001> it returns the string "var1"
<andkerosine> Which Ruby are you on?
<eggman2001> 1.9.3
<andkerosine> 1.9.3p0 :006 > a = 1
<andkerosine> => 1
<andkerosine> 1.9.3p0 :007 > :"var#{a}"
<andkerosine> => :var1
<andkerosine> Admittedly, I don't think symbols can be declared globally, so you'll likely have to use a hash to store your variables...
<eggman2001> I want it to return the value of var1. so I'd like it to return 123
<andkerosine> But it's how to do it if you don't want to get into eval ickyness.
rue has joined #ruby-lang
<eggman2001> okay thanks
<andkerosine> 1.9.3p0 :008 > vars = {var1: 123}
<andkerosine> => {:var1=>123}
<andkerosine> 1.9.3p0 :009 > a = 1
<andkerosine> => 1
<andkerosine> 1.9.3p0 :010 > vars[:"var#{a}"]
<andkerosine> => 123
<eggman2001> wow that's pretty ugly :p
<andkerosine> Alas, alas.
<eggman2001> at least for me
<ankurgel> :D
<andkerosine> You're taking an ugly approach.
<andkerosine> ankurgel: I think the problem becomes a /whole/ lot clearer if you extract out the anagram checking.
<ankurgel> extract out? as in separate function?
<andkerosine> Mm-hmm.
<andkerosine> Have a method that returns whether or not two strings are anagrams, and then another which does the combining by taking each word, grabbing its anagrams from the remaining list, and then popping them out of the list so that they don't get processed again.
<ankurgel> I can declare function within a function, right?
<andkerosine> You don't want [['racs', 'scar']] and [['scar', 'racs']]
<ankurgel> and call internal function, outside.
<andkerosine> Yes, but don't. : )
<andkerosine> It's never good practice, really.
<andkerosine> If you ask the question because it strikes you as a good idea to keep related functions together, bravo, but do it as a class or module.
tyman has joined #ruby-lang
<ankurgel> hm, I have to keep it in a single function, function is provided with list of words, it returns back OUTPUT
postmodern has joined #ruby-lang
<andkerosine> That is, you are only given access to the internal structure of the combine_anagrams method?
<ankurgel> yes.
<andkerosine> Ah.
jkyle has joined #ruby-lang
<ankurgel> have to submit this one actually. They only require this function to judge.
<andkerosine> Mm-hmm.
chessguy has joined #ruby-lang
<andkerosine> #select is /the/ function to use here.
<dominikh> *method
<injekt> method method method
<andkerosine> Got me.
<injekt> psh
<dominikh> injekt: hah!
<injekt> dammit dominikh
<ankurgel> haha
* andkerosine seppuku.
<injekt> of all people
<injekt> fml
<ankurgel> but, select will only select a group at a time, no?
<andkerosine> That's what you want.
<andkerosine> You want to go through each word in the lest, select its anagrams from the rest, and then go to the next.
<andkerosine> *list
<ankurgel> group can be framed for other anagram cases too.
<ankurgel> yeah
<andkerosine> Right, #select inside of an iteration.
<ankurgel> but, again, that select will provide me with that sorted array matching result.
<ankurgel> I have to show the original words from list.
<ankurgel> or probably I can use array addressing to address that array instead.
<injekt> what are you doing? the backtrace is impossible to read
Bwild has joined #ruby-lang
<ankurgel> injekt, me?
<andkerosine> It must take in an array of words and return them grouped as anagrams, no?
<injekt> ankurgel: sure
<ankurgel> andkerosine, yes. whatever strings are anagram, group'em.
rushed has joined #ruby-lang
<andkerosine> Mm-hmm. Then iterating over the word list, #select-ing the anagrams, and pushing them into the return array is the solution.
<ankurgel> injekt, yeah, my bad, I messed that sentence
<andkerosine> ankurgel: My solution uses #each, #select, #split, #sort, and #uniq. : )
<dreinull> is there something like tconsole for any app, not just rails?
<ankurgel> andkerosine, I'm not aware of #uniq
<andkerosine> [1,2,2,3,3,3,4].uniq == [1, 2, 3, 4]
<ankurgel> ohh
<ankurgel> is it like, ruby has goddamn everything one can ask for? :P
Bwild has joined #ruby-lang
<andkerosine> Rather than the ickiness of removing words as they're encountered, my solution just does them all, but then removes the duplicates.
<andkerosine> ankurgel: Yes, that is pretty much the case.
<Spooner> Why not use #permutation: "fish".split(//).permutation.map(&:join)
<ankurgel> and how it groups at last?
rue has joined #ruby-lang
<andkerosine> It initializes an empty results array, then pushes into it with <<
<andkerosine> #select returns an array, so that's what gets pushed in.
brianpWins has joined #ruby-lang
<andkerosine> Spooner: The goal isn't to find all possible anagrams...
<ankurgel> andkerosine, permuatation is another method present?
<andkerosine> In mine, no.
<andkerosine> It's not what's needed in this case.
<injekt> this has really been taken out of control
<andkerosine> injekt: What has...?
<ankurgel> okay. [offtopic] log this chat in xchat? Forgot to put it on log earlier and now half of discussion is gone[/offtopic]
<andkerosine> Sorry, Pidgin user 'til I die.
<Spooner> andkerosine: Just seemed to be odd that it was missing from a conversation about anagrams and may have been overlooked.
<andkerosine> Ah, fair enough.
<injekt> andkerosine: from what I can see, you guys have been talking about this since before my backtrace knows about
<injekt> which is a long time
<andkerosine> You have apparently forgot what it looks like to learn...
<andkerosine> +ten
<andkerosine> Which, I mean, kudos to you, I guess.
<dominikh> injekt: s/backtrace/backlog/ – this isn't an exception :P
<andkerosine> Are you selling your hair?
S1kx has joined #ruby-lang
S1kx has joined #ruby-lang
<injekt> eh
<injekt> dominikh: :D
<injekt> dominikh: mine looks more like an exception right now..
<dominikh> hehe
<ankurgel> andkerosine, still couldn't figure out how you are combining use of #select and #uniq
<dominikh> a python exception, everything in the wrong order
<ankurgel> #uniq gave me unique results from array,
<injekt> andkerosine: I haven't forgotten that at all, but the conversation appears convoluted. That was my only concern
<injekt> dominikh: :D
<andkerosine> Convoluted because it's pedagogic.
<ankurgel> but, how am I supposed to use it for making out groups from original array.
havenn has joined #ruby-lang
<andkerosine> I do not support giving a man too many fish.
<ankurgel> :D
<injekt> andkerosine: Pedagogic does not mean it's convoluted at all
<andkerosine> Still, enjoy this one: https://gist.github.com/1968705
<injekt> there's nothing wrong with simplifying things
skipper has joined #ruby-lang
<andkerosine> Optimal learning isn't always about simplification.
<injekt> you're hard work
<andkerosine> ...?
darkf has joined #ruby-lang
burns180_ has joined #ruby-lang
<andkerosine> ankurgel: Nothing clicking?
<ankurgel> clicked.
<ankurgel> [["acrs", "acrs", "acrs"], ["for"], ["aeoopstt"], ["foru"], ["acemrs", "acemrs"]]
<ankurgel> got this, now. :)
<ankurgel> must pair from original list instead.
<ankurgel> doing that now
<ankurgel> andkerosine, with that kickass guidance of you. It's all what is present on my vi: https://gist.github.com/1968795
<ankurgel> s/you/yours*
<andkerosine> That... didn't work?
<ankurgel> see the output in that gist.
<ankurgel> I need to pair original elements: [["cars", "racs", "scar"], ["four"], ["for"],["potatoes"], ["creams", "scream"]]
<andkerosine> Yes.
<andkerosine> word_copy isn't getting used.
<ankurgel> exactly
<andkerosine> That is your enemy.
<ankurgel> but, it was needed to save that somewhere, no?
<andkerosine> Not at all.
<ankurgel> Then, how do I get original elements back?
<andkerosine> Rather, use the original, and instead do your anagram check /inside/ the #select.
<ankurgel> unless I'm creating hash out of them.
<ankurgel> probably
<andkerosine> No need for a hash.
<ankurgel> hm
<ankurgel> ok
<ankurgel> I can include an iterator within an iterator?
<ankurgel> in blocks*
<andkerosine> Bam!
<ankurgel> ^Affirmation? :)
<andkerosine> Oh, yes.
<andkerosine> 'Tis the secret.
<andkerosine> No need for results /and/ arr, though.
<ankurgel> AND NOW I SHALT HAZ IT
<ankurgel> :)
<andkerosine> Also, #downcase and #join are superfluous.
<ankurgel> join is to bring back those tiny little pieces back..
<andkerosine> ['a', 'c', 't'] == ['a', 'c', 't'], so no sense in joining them.
<ankurgel> so that they can be checked against for anagrams..
<ankurgel> oh
<ankurgel> compare of them will give true?
<andkerosine> Mm-hmm.
<ankurgel> cool
<andkerosine> Ruby doesn't have to know they're words, really.
<andkerosine> Just that they're made of the same pieces.
<ankurgel> after using #select, one word from original_array is pushed in,
<ankurgel> I'm now supposed to use an iterator within taht,
<ankurgel> which will check for anagram.
<ankurgel> Legit?
<andkerosine> Not quite.
<andkerosine> #select is where pretty much everything should happen.
<ankurgel> MIND==SCREWED :D
<andkerosine> The recipe: prepare empty results array, iterate over each word and #select everything that is an anagram of that word (including the word itself, which should make things a bit easier), push the results of that #select into the array.
<andkerosine> The array will then contain duplicates wherever an anagram was found, so return the array with duplicates removed.
<injekt> my face hurts when I look at this channel
<ankurgel> [[abc,def],[def,abc]].uniq=[[abc,def]]?
<injekt> try it?
<injekt> open irb
<injekt> try these things
<ankurgel> injekt, he was faster than irb, so, well.. :D
<ankurgel> s/was/is
<injekt> nothing is faster than irb
<dominikh> pry is
<injekt> tololol stfu
<dominikh> tololol? what are you, asian?
<injekt> possibly
<ankurgel> hm.. not quite.
Weems has joined #ruby-lang
Weems has joined #ruby-lang
<injekt> anyone got an r i can borrow?
<dominikh> ask the pirates
<injekt> har
<andkerosine> ankurgel: No, but if you sort the initial word list before you iterate, then all of the anagram arrays will be in order, which means #uniq will remove them properly.
<andkerosine> Well, no, a sort really isn't necessary. You're iterating over the word list in the same order each time, so the anagram arrays that get pushed will always be in the same order.
<ankurgel> overkill. It's almost morning here. Lost sleep session :O
<ankurgel> fuzzy fuzzy fuzzy
<injekt> soo many words, soo little code
<ankurgel> yes, but I learnt/is_learning a lot, that matters. :)
<andkerosine> I support that notion.
<andkerosine> Still, it's homework, feels indecent to provide a complete solution.
<ankurgel> definitely, I'll have to do it myself.
kain has joined #ruby-lang
<ankurgel> atleast, pretentiously :P
<andkerosine> Mm-hmm.
<ankurgel> already got help in every line, so can't say that I'm making it myself.
<andkerosine> Try to have it going in your conscious mind as you fall asleep.
<andkerosine> Sort of hard to do intentionally, but it's glorious when it happens.
<shevy> lol
<andkerosine> I love waking up and remembering what code I was thinking about.
<ankurgel> hahaha
<shevy> cool
<shevy> code tends to make me angry
<ankurgel> this one was interesting. I had one or two incidents, when I slept giving up on some program,
<injekt> shevy: that's good
<ankurgel> and after waking up it automatically striked!
<andkerosine> It is a wondrous experience.
<andkerosine> shevy: Builds character... or something.
<shevy> yeah good for workout, I use this energy to keep fit and punch things in my surroundings
burns180 has joined #ruby-lang
<erikh> disregard irc, acquire commits
<injekt> translate: disregard irc, WRITE SOME FUCKING CODE
eggman2001 has quit [#ruby-lang]
<injekt> wrong window
<andkerosine> disposition[:injekt] = "" << 0x1F4A9
looopy has joined #ruby-lang
ankurgel has joined #ruby-lang
<ankurgel> aah. got disconnected, I guess.
<andkerosine> So... it has come to this.
<ankurgel> Ha. Well, sometimes connection just loses you. :
<ankurgel> :D
<andkerosine> It is known.
<ankurgel> andkerosine, aren't you dozy till yet? Or is it not night there?
<andkerosine> Lololol.
<andkerosine> I mean, it's only 1820, but sleep and I haven't gotten along in quite some time.
<andkerosine> Strange for most, probably, but I just don't really /like/ sleep. It's boring. : )
<ankurgel> well, this is what goes with me. When I get in sleep-mode, I wonder why other person is not sleeping as well. :D
<andkerosine> You are human, after all.
<ankurgel> You are not? :O :P
<andkerosine> Oh, I am, I guess.
<shevy> hmm
<shevy> how can we be sure?
<andkerosine> I only meant that you have a human brain, the universe's hitherto most advanced projection system.
<ankurgel> I sleep little to. But even that little sleep is SO NEEDED.
<ankurgel> too*
<shevy> the universe is really big
<andkerosine> I tend to go maybe thirty hours straight, then I sleep, wake up to piss, and go, "Hm, could wake up..."
<andkerosine> 30 on/4-5 off...
<ankurgel> 4-5 hrs daily for few days. And it gets to breakpoint someday and I end up sleeping for hours.
<andkerosine> Sounds pretty familiar, yep.
<ankurgel> w.o.w
<andkerosine> shevy: We can only pretend we understand.
<andkerosine> Oh... sorry, took your comment out of context.
<shevy> andkerosine well I dont really understand the universe
<ankurgel> This universe talk is now reminding me of TBBT.
<andkerosine> The word "universe" almost always makes me think about the absurdity of matter in general.
<shevy> perhaps people in 1000 years will read old chat logs and wonder a lot about how people used to be 1000 years ago
<andkerosine> shevy: Definition of history.
<ankurgel> Well, universe is endless. A complete arbitrary person holds the potential to be surprising.
<andkerosine> Universe /might/ be endless.
<ankurgel> hm
<andkerosine> Big Bang/Crunch strikes me as a really elegant explanation.
twittard has joined #ruby-lang
<shevy> what is the crunch
<shevy> big bang I know but crunch?
<andkerosine> The complete opposite.
<shevy> hmm
<ankurgel> like contraction of everything ?
<andkerosine> Mm-hmm.
<ankurgel> into one-mass ball. BOOM
<andkerosine> Things are spreading out and getting locally weaker, gravitationally, but black holes form all the time, which reverse that effect.
<andkerosine> If enough black holes come into existence, they'll start pulling each other, tiny ball of matter, too condensed, explode again.
<andkerosine> Lather, rinse, repeat.
<andkerosine> It's beautiful, but it leaves the prime mover unsolved.
<ankurgel> recursive universe is recursive.
<shevy> admit you just like this more than a universe that expands until it has diluted all its energy ;)
<shevy> though I wonder a little where the black holes pop out from
<andkerosine> No, that's also cool, just less convincing given what is known about quantum foam.
<shevy> foam?
<shevy> man
<andkerosine> Ah, they don't "pop out", per se, my wording was off.
<shevy> next time I am taking a bath, I will pick some quantum foam with me
<andkerosine> You /are/ quantum foam.
<andkerosine> : )
<ankurgel> ^what #ruby-lang is turning to now. :D
erpuds has joined #ruby-lang
<andkerosine> Programmer + universe = joyous mental exercise.
<ankurgel> +1
<ankurgel> Ok, I must probably call it night now. Scheduled to complete today's last problem tomorrow then.
<ankurgel> andkerosine, Thank you so much for all your help!!
<ankurgel> andkerosine, seriously grateful for your patient and awesome replies. :D
<andkerosine> In all sincerity, it was my pleasure.
<andkerosine> I will never speak to you again if you don't get those anagrams grouped, though.
<andkerosine> : P
<ankurgel> and thanks to shevy as well.
<ankurgel> NOOO
<shevy> bye
<ankurgel> I'll do it.
<ankurgel> :D
<andkerosine> This I do not doubt.
<ankurgel> or will make you do it for me. #YouPrefer
<andkerosine> I've completely forgotten how I did it.
<andkerosine> #permutation, maybe?
<ankurgel> next day awaits for regeneration.
<andkerosine> Bring it!
<andkerosine> Night, man.
<ankurgel> bye guys. :) Night.
curtism has joined #ruby-lang
<andkerosine> injekt: How to improve?
setmeaway has joined #ruby-lang
<Spooner> andkerosine: words.map {|word| word.select {|w| word.split(//).sort == w.split(//).sort }.uniq
<andkerosine> Ah... wow.
burns180_ has joined #ruby-lang
<andkerosine> That was silly.
JEG2 has joined #ruby-lang
<andkerosine> I was in keep-it-simple mode, I guess.
<manveru> words.uniq{|w| w.split('') }
<andkerosine> For grouping anagrams?
<manveru> sort, sorry
<manveru> grouping?
havenn has joined #ruby-lang
<andkerosine> Taking an array of words and creating an array of arrays, the inner ones containing the anagrams.
<Spooner> What is the input/output required (before it can be simplified).
<andkerosine> Words come in, groups of anagrams go out.
<andkerosine> Wow.
<andkerosine> I maybe need sleep.
<andkerosine> *go in, *come out
jbvp has joined #ruby-lang
<Spooner> ["ab", "ba", "cc"] => [["ab", "ba"], ["cc"]] you mean?
<jbvp> hi
<andkerosine> Yezzir.
<Spooner> Oh.
<manveru> oh
<manveru> >> %w[mary army ab ba cc].group_by{|w| w.chars.sort }.values
<Spooner> I didn't work that out before. Simpler is: words.group_by {|w| w.split(//).sort }.values
<manveru> => [["mary", "army"], ["ab", "ba"], ["cc"]]
<manveru> :)
<andkerosine> Nice.
<Spooner> You typed faster than me, manveru :)
<andkerosine> #group_by is damned convenient.
<manveru> indeed it is
<andkerosine> manveru: Do you feel inheriting is always bad form?
<manveru> andkerosine: no
<andkerosine> Inheriting from Hash to create persistent config? : )
<manveru> yes
<andkerosine> Damn.
<manveru> lol
<Spooner> Just wrap it.
<andkerosine> I have to, at some point, modify []=
<andkerosine> To my knowledge, that either means inheriting, or attaching []= directly to the config object.
<manveru> why?
<andkerosine> Because the intended effect is to write the hash to disk upon changes.
<manveru> class Conf; def initialize; @c = {}; end; def []=(k,v) @c[k] = v; persist! end; def persist!; stuff; end; end
<manveru> andkerosine: also, there already exist around 4 implementations of that in the stdlib
<Spooner> When I've used that sort of write-to-disk config, I've exposed self[a, b, ...]= on the wrapper, so that you aren't going through hashes directly.
wallerdev has joined #ruby-lang
<manveru> there is YAML::Store, SDBM, GDBM, DBM
<manveru> also PStore
<andkerosine> I'm going for minimal dependencies.
<andkerosine> I want it to be dead-simple for people to use.
<manveru> it's fuckin stdlib, how minimal can you get?
<Spooner> stdlib is about as minimal as it can be.
<andkerosine> Oh...
<dominikh> if you want minimal maybe you should use perl, I heard it's installed by default on most systems!
<manveru> sorry, i'm tired ^^;
<manveru> anw, the *DBM ones are really recommended, since they don't have to rewrite the whole data every time it changes
<manveru> YAML::Store is just a wrapper for PStore, which uses Marshal by default
<manveru> but since everyone and their dog are in love with mongoriakcachedcouchdb they get no love :(
<andkerosine> Yajl's fast. : )
<manveru> not if you have to write the whole thing every time
<manveru> HDD is slow
<Spooner> Depends. If it is a 10-line config file, I doubt it matters.
<manveru> :)
<manveru> anw, pick your poison
<manveru> gn8
Heimidal has joined #ruby-lang