<shevy>
mksm not a builtin one but you can always extend Array
yumatov joined #ruby-lang
Defusal joined #ruby-lang
Defusal joined #ruby-lang
<ryanf>
hmm
<ryanf>
anyone have much experience using the event_machine gem?
<ryanf>
I'm still getting my head around how you're supposed to use it in practice
hahuang65 joined #ruby-lang
canuck3141 joined #ruby-lang
rhizmoe joined #ruby-lang
dhruvasagar joined #ruby-lang
Aaaarg joined #ruby-lang
zedUNDginger joined #ruby-lang
JohnBat26 joined #ruby-lang
yxhuvud joined #ruby-lang
<zedUNDginger>
ryanf: cirwin does
<zedUNDginger>
;)
<ryanf>
wtf why isn't he in here
cirwin joined #ruby-lang
<zedUNDginger>
cirwin: welcome to dead house
<cirwin>
I'm happy to phlog dead houses
<ryanf>
oh durr I am an idiot
<ryanf>
no wonder banister said that
<ryanf>
I asked about event_machine and I meant state_machine
<ryanf>
:)
<ryanf>
I already knew that you used eventmachine
<cirwin>
I don't know about state machine with an underscore
<ryanf>
yeah me neither , I think I'm getting the hang of it though
<zedUNDginger>
ryanf: isn't state_machine of those :icky => :apis [That], :pretends_to_be_such_a_nice_dsl => :but is really just a bunch of :hash arguments stupidly put together
<ryanf>
yes
<ryanf>
although it's actually a pretty good fit
<zedUNDginger>
ah ok
<ryanf>
what with arrows and state transitions
<ryanf>
being kind of related concepts
burgestrand joined #ruby-lang
<zedUNDginger>
ryanf: did you see my cute state machine implementation?
<dkannan>
zedUNDginger: sure. all the time - actually it is the wallpaper on my laptop right now
<dkannan>
zedUNDginger: mind answering the question now :-)
<zedUNDginger>
dkannan: if you turn it into a method u can ;)
<ryanf>
dkannan: the reason there is no such restriction on ivars is because they're resolved differently, not because of anything about the undefined error
<ryanf>
when you define a proc, it closes over whatever locals happen to be around at the time, and that defines its local environment whenever it's invoked later
<ryanf>
I think if you try changing encoded_time after defining the second proc, you'll find that the output stays the same
<ryanf>
changing as in reassigning
<dkannan>
ryanf: ok checking
<zedUNDginger>
ryanf: it'll change
<ryanf>
really? damn
Xzyx987X joined #ruby-lang
<zedUNDginger>
matz was gonna make it a copy but said he wanted to to stay true to lisp and make them one and the same local
burgestrand joined #ruby-lang
<dkannan>
yup it changes
<ryanf>
oh ok, disregard that :)
<ryanf>
anyway I don't know of a way to add stuff to the binding after the proc is defined, zedUNDginger might though
<ryanf>
hmm
<ryanf>
zedUNDginger: inject_local in pry seems suspiciously similar, I can't get it to work in this case though. does that depend on where the binding came from?
<ryanf>
oh it's because later pry evaluation happens on the same binding object, isn'ti t
<ryanf>
that makes sense
<zedUNDginger>
ryanf: yeah same binding
<zedUNDginger>
ryanf: this almost works: my_proc.binding.eval("encoding_time = 10")
<zedUNDginger>
my_proc.call
<zedUNDginger>
but Proc#binding generates a fresh binding each time from the proc's environment
<ryanf>
yeah that makes sense
workmad3 joined #ruby-lang
robotmay joined #ruby-lang
heftig joined #ruby-lang
mqt joined #ruby-lang
thrcka joined #ruby-lang
yorickpeterse joined #ruby-lang
resetexistence joined #ruby-lang
mytrile joined #ruby-lang
apeiros_ joined #ruby-lang
zedUNDginger joined #ruby-lang
roadkith joined #ruby-lang
Codif joined #ruby-lang
woollyams joined #ruby-lang
srbartlett joined #ruby-lang
yorickpeterse joined #ruby-lang
gnufied joined #ruby-lang
tbuehlmann joined #ruby-lang
snafoo joined #ruby-lang
snafoo joined #ruby-lang
sirfilip joined #ruby-lang
<sirfilip>
morning
sirfilip1 joined #ruby-lang
adambeynon joined #ruby-lang
molgrew joined #ruby-lang
robotmay joined #ruby-lang
ammar01 joined #ruby-lang
dnjaramba joined #ruby-lang
sirfilip1 left #ruby-lang
thrcka joined #ruby-lang
Foxmaster joined #ruby-lang
roadkith joined #ruby-lang
dabradley joined #ruby-lang
srbartlett joined #ruby-lang
Aaaarg joined #ruby-lang
havenn joined #ruby-lang
saLOUt joined #ruby-lang
benanne joined #ruby-lang
workmad3 joined #ruby-lang
srbartlett joined #ruby-lang
dave_miles joined #ruby-lang
havenn joined #ruby-lang
marcostoledo joined #ruby-lang
ksinkar joined #ruby-lang
<andrewvos>
Guys I just found a good article at Hacker News!
<andrewvos>
Oh wait. It's from 2000.
woollyams joined #ruby-lang
<shevy>
lol
Mch1 joined #ruby-lang
toretore joined #ruby-lang
<dr0id>
that's recent!
<zedUNDginger>
dr0id: hello
<dr0id>
hi zed
<shevy>
one two three
<shevy>
ruby and the bee
<shevy>
four five six
<shevy>
ruby is in the mix
sepp2k joined #ruby-lang
takaokouji joined #ruby-lang
mrchrisadams joined #ruby-lang
<zedUNDginger>
shevy:
<zedUNDginger>
I'm waiting patiently,
<zedUNDginger>
Hoping that I can be...in your mix
<zedUNDginger>
It's you that I adore,
<zedUNDginger>
Just wait, that's so much more in my mix
schitzo joined #ruby-lang
<shevy>
now you see why acid should be avoided
workmad3 joined #ruby-lang
<zedUNDginger>
All you know
<zedUNDginger>
I'm the best you know
<zedUNDginger>
Put me in your mix
<zedUNDginger>
I wanna be right there
<zedUNDginger>
I know just what you like
<zedUNDginger>
Give me a chance tonight...in your mix
<zedUNDginger>
I need to be there
<muzone>
i can give u a chance
<muzone>
what u gonna do in my mix though, sing? rap?
<flashgig>
I'm having trouble getting the Anemone gem to work on Ruby 1.8.7 - might someone be kind / awesome / epic / your-adjective-of-choice to help point in the right direction of where I'm going wrong?
<dkannan>
flashgig: check that the gem is required
<dkannan>
flashgig: ie require 'anemone' i think
ltd-- joined #ruby-lang
<flashgig>
Thank you dkannan, I have the require in place but still I error. I have a very simple test script that this is failing on pastebinned here in case it helps ^_^ http://pastebin.com/xD4ytVmH
ryo84 joined #ruby-lang
JohnBat26 joined #ruby-lang
takaokou_ joined #ruby-lang
<manveru>
flashgig: you called you file anemone.rb ?
<flashgig>
indeed I did. Just changed it now and..... ah... *FACEPALM*
<flashgig>
I *did* oroginally have this problem in a differently named file though - so I must have satisfied a depency somewhere along th eline
<manveru>
well, remove the $: << '.'
<manveru>
you're on 1.9?
<flashgig>
1.8.7 I'm afraid due to some annoying dependencies
workmad3 joined #ruby-lang
<manveru>
you mean ruby-debug?
<flashgig>
Truthfully i'm not sure - I've inherited a codebase that I'm working my way through trying to understand and improve it. The original dev, who's only available to me a day a week currently, has told me that bumping to 1.9 will result in various compatibility issues but, and here's the punchline, he's not sure in what areas / gems or why T__T
<manveru>
heh
<manveru>
well, because he hasn't tried it
<manveru>
anw, guess you should understand the app and ruby first
<flashgig>
I think you speak the truth! I'll be charged with trying it sooner or later but, as you say, only once I've got the app wrapped around my head. It's an interesting learning experience all the same!
kitallis joined #ruby-lang
<zedUNDginger>
flashgig: try running it in 1.9 and see what errors u get
ltd- joined #ruby-lang
sulo_ joined #ruby-lang
ltd-- joined #ruby-lang
felipegb joined #ruby-lang
prpr joined #ruby-lang
heftig joined #ruby-lang
zmack joined #ruby-lang
<prpr>
What's the best way to do a deep copy efficiently? I've been reading into Marshalling, but that seems somewhat efficient.
<prpr>
or is typically better to write a custom copy method
<zedUNDginger>
prpr: initialize_copy
<zedUNDginger>
if u want dup to do a deep copy
yumike joined #ruby-lang
jensn joined #ruby-lang
uniqanomaly_ joined #ruby-lang
ltd- joined #ruby-lang
<prpr>
zedUNDginger: what core classes implement that?
<zedUNDginger>
prpr: it's a hook u have to implement it yourself
<prpr>
that makes sense
<rue>
It's not really a hook in the sense that you can freely override it
Natch| joined #ruby-lang
<prpr>
does marshalling typically have a high overhead?
<rue>
Core classes' #dup and #clone will *use* it, so you can't just substitute your own without reimplementing the other copy semantics
<prpr>
does that just entail calling super?
takaokouji joined #ruby-lang
Foxmaster joined #ruby-lang
yumike joined #ruby-lang
Pip joined #ruby-lang
<rue>
No, unless you're inheriting
<rue>
Just implement a #deep_copy
woollyams joined #ruby-lang
yumike joined #ruby-lang
dnjaramba joined #ruby-lang
dnjaramba joined #ruby-lang
jensn_ joined #ruby-lang
<andrewvos>
nooooooo
<shevy>
hmm this regex /^(\w+):/ matches to a string like "cat:" ... how do I also match to "cat?:" where the "?" character can be optional? I.e. sometimes not be part of the string
<andrewvos>
\??
m0wfo joined #ruby-lang
saLOUt joined #ruby-lang
<shevy>
hmm odd
<shevy>
I could swear I tried that
<shevy>
yay! works, thanks andrewvos
<andrewvos>
Pleasure shevy.
replore joined #ruby-lang
sulo joined #ruby-lang
m0wfo joined #ruby-lang
burgestrand joined #ruby-lang
zedUNDginger joined #ruby-lang
hebz0rl joined #ruby-lang
tommyvyo joined #ruby-lang
adambeynon joined #ruby-lang
shevy joined #ruby-lang
Spooner joined #ruby-lang
petercooper joined #ruby-lang
kedare joined #ruby-lang
gnufied joined #ruby-lang
wyhaines joined #ruby-lang
mark_locklear joined #ruby-lang
workmad3 joined #ruby-lang
whitequark joined #ruby-lang
malev joined #ruby-lang
Bwild joined #ruby-lang
kvs joined #ruby-lang
cyri_ joined #ruby-lang
yumike joined #ruby-lang
yfeldblum joined #ruby-lang
DEac- joined #ruby-lang
hagabaka joined #ruby-lang
hagabaka joined #ruby-lang
<shevy>
does one of you happen to know
<shevy>
whether CodeRay could be used to ... colourize ruby code in a terminal?
<erikh>
you'd think with the funny spelling of pigments that'd be obvious
<shevy>
who knows. people call their project "god" or "unicorn"
<erikh>
point taken
<shevy>
hmm perhaps I should try the poor man's approach and just use .gsub
<steveklabnik>
now you have two problems
<shevy>
:(
<erikh>
"dns": {
<erikh>
"domain": "node.wfops.com",
<erikh>
shit
robbrit joined #ruby-lang
gokulnath joined #ruby-lang
tomzx joined #ruby-lang
takaokouji joined #ruby-lang
yumike joined #ruby-lang
benanne joined #ruby-lang
gnufied1 joined #ruby-lang
imajes joined #ruby-lang
gnufied joined #ruby-lang
dv310p3r joined #ruby-lang
diegoviola joined #ruby-lang
rippa joined #ruby-lang
jwill joined #ruby-lang
NiTr0 joined #ruby-lang
rolfb joined #ruby-lang
MistyM joined #ruby-lang
slyphon joined #ruby-lang
slyphon joined #ruby-lang
scampbell joined #ruby-lang
Foxmaster joined #ruby-lang
kmeehl joined #ruby-lang
nofxx joined #ruby-lang
leonL joined #ruby-lang
Guedes joined #ruby-lang
Guedes joined #ruby-lang
dr0id left #ruby-lang
znz_v joined #ruby-lang
znz_v joined #ruby-lang
alindeman joined #ruby-lang
<shevy>
hmmm should foo.gsub! be used rather than foo = foo.gsub ... for some reason I seem to often do the second one
kmeehl joined #ruby-lang
<akahn>
What would be the most idiomatic way to map over a hash, modifying its keys?
dejongge joined #ruby-lang
<samuelkadolph>
shevy: If you created the string yourself might as well use gsub! for the speed
<shevy>
ok samuelkadolph
srbaker joined #ruby-lang
outoftime joined #ruby-lang
burgestrand joined #ruby-lang
dhruvasagar joined #ruby-lang
ecin joined #ruby-lang
Skif joined #ruby-lang
dv310p3r joined #ruby-lang
steph021 joined #ruby-lang
steph021 joined #ruby-lang
outoftime joined #ruby-lang
empity joined #ruby-lang
ryanf joined #ruby-lang
flip_digits joined #ruby-lang
kain joined #ruby-lang
comboy joined #ruby-lang
<steveklabnik>
akahn: inject.
<steveklabnik>
building a new hash.
<akahn>
steveklabnik: thanks
<steveklabnik>
it's sort of odd to think of it, but it does make sense. inject is takes a list of somethings and gives back a single something; it just so happens that single something is a list.
zedUNDginger joined #ruby-lang
cldwalker joined #ruby-lang
<andrewvos>
steveklabnik: I'm busy working with a rest api that would make you lose your shit :)
<steveklabnik>
andrewvos: i bet it would. :)
<steveklabnik>
i'm writing today
<andrewvos>
Good good
<steveklabnik>
i think i'm really happy with the Big Picture
<any-key>
I've got a mystery I need help with: class Foo < Struct.new(:id); def bar; puts id; id ||= 0; puts id; end; end
<any-key>
When I run "Foo.new(1).bar", the output is 1 followed by 0
<any-key>
Is there some kind of reasonable explanation as to why this is happening?
<lianj>
id ||= 0 assigns the local variable id
<any-key>
but referring to "id" returns 1
<any-key>
they should be referring to the same variable
sulo joined #ruby-lang
<steveklabnik>
self.id ||= 0;
<any-key>
interesting
<any-key>
that makes sense, except for the fact that "puts id" seems to refer to self.id
<steveklabnik>
right
<steveklabnik>
at that point, no variable has been defined
<steveklabnik>
so it calls the method
<lianj>
self.id and self.id= is not really a variable but get/setter methods
<steveklabnik>
then assignment then creates a new local
<any-key>
ah
<any-key>
that makes sense
<any-key>
thanks!
<steveklabnik>
and so it takes presedence
<steveklabnik>
:D
<steveklabnik>
it's slightly tricky.
<any-key>
steveklabnik: I saw your talk on Shoes at LSRC
<any-key>
great talk
<steveklabnik>
thank you!
<steveklabnik>
i gave a slightly different version at RubyConf
plusk joined #ruby-lang
<akahn>
steveklabnik: well, that makes me sad, because to me, inject means "fold a list of values up into a single value," and map should return the same type it was called on
<steveklabnik>
akahn: folds return lists all the time, at least in the haskell i've written. ;)
chessguy joined #ruby-lang
<akahn>
sure, it depends on the function you pass it, but the purpose is to process/distill a list into some calculated result
<steveklabnik>
right. your calculated result is a hash.
kain_ joined #ruby-lang
* steveklabnik
shrugs
burgestrand joined #ruby-lang
nuclearsandwich joined #ruby-lang
FrostyAcres joined #ruby-lang
tvl joined #ruby-lang
retro|cz joined #ruby-lang
dhoss joined #ruby-lang
macmartine joined #ruby-lang
rayners joined #ruby-lang
cirwin joined #ruby-lang
plusk joined #ruby-lang
ecin joined #ruby-lang
ecin_ joined #ruby-lang
m0wfo joined #ruby-lang
amerine joined #ruby-lang
niklasb joined #ruby-lang
* rue
nerdrages
<steveklabnik>
?
sepp2k joined #ruby-lang
<erikh>
raaaaaaaaaage
robotmay joined #ruby-lang
<rue>
steveklabnik: Trying to extricate from The Registrar That Shall Not Be Named
<andrewvos>
I'm wanting to add an extra value to the results.
<andrewvos>
And I'm wondering about possible approaches.
<andrewvos>
I could attach a property on to the searchables items.
<andrewvos>
By the way I need to add an object on to each item
<andrewvos>
or I could make the developer create actual Searchable item classes himself and pass them into search.
<andrewvos>
Thoughts?
gearaholic joined #ruby-lang
Pip joined #ruby-lang
Pip joined #ruby-lang
Manhose joined #ruby-lang
mrsolo joined #ruby-lang
tjgillies left #ruby-lang
vmil86 joined #ruby-lang
yorickpeterse1 joined #ruby-lang
m0wfo joined #ruby-lang
towski joined #ruby-lang
thegeekinside joined #ruby-lang
DEac- joined #ruby-lang
dinesh joined #ruby-lang
niklasb joined #ruby-lang
saysjonathan joined #ruby-lang
yorickpeterse joined #ruby-lang
cirwin joined #ruby-lang
ivanoats joined #ruby-lang
headius joined #ruby-lang
hahuang65 joined #ruby-lang
sepp2k joined #ruby-lang
cyri_ joined #ruby-lang
saysjonathan joined #ruby-lang
<manveru>
you dog is in koma?
Fretta joined #ruby-lang
<outoftime>
if I want to run something at_exit in my process, but not in any child processes, is there a more elegant way to do that than just holding a reference to the pid outside the at_exit block and comparing it to the pid inside the block?
<manveru>
outoftime: nope
<outoftime>
manveru: cool, just checking my sanity, thanks : )
<manveru>
andrewvos: i still don't get what you mean with extra value
solars joined #ruby-lang
scampbell joined #ruby-lang
tty234 joined #ruby-lang
demas joined #ruby-lang
arubis joined #ruby-lang
darkf joined #ruby-lang
DEac- joined #ruby-lang
mrsolo joined #ruby-lang
DRCALKIN joined #ruby-lang
malev joined #ruby-lang
arubis joined #ruby-lang
Carnage\ joined #ruby-lang
MistyM joined #ruby-lang
ivorybishop joined #ruby-lang
kitallis joined #ruby-lang
<andrewvos>
manveru: So I return an array of items that matched the search result. I want each one to have a "blurb" property on them.
<andrewvos>
manveru: Similar to how google shows search results.
amerine joined #ruby-lang
livinded joined #ruby-lang
elux joined #ruby-lang
<elux>
hey gents
<elux>
does ruby-debug19 work with 1.9.3?
<elux>
thats the last thing holding me back from moving to 1.9.3 ....
<yorickpeterse>
Use Pry :)
<elux>
i will look it up...
<elux>
but im just used to ruby-debug19
<elux>
neat.. pry seems very simple
<elux>
just drops you into an irb console..which is really what i want
<yorickpeterse>
:)
<yorickpeterse>
If you're looking for breakpoints, just dump "binding.pry" somewhere in your code (and make sure Pry is loaded) and you're good to go
nofxx joined #ruby-lang
lsegal joined #ruby-lang
<elux>
neat
dr_bob joined #ruby-lang
rolfb joined #ruby-lang
jmontross1 joined #ruby-lang
wyhaines joined #ruby-lang
andrewhl joined #ruby-lang
m0wfo joined #ruby-lang
ilyam joined #ruby-lang
nuclearsandwich joined #ruby-lang
mrsolo joined #ruby-lang
tty234 joined #ruby-lang
ilyam_ joined #ruby-lang
cyri_ joined #ruby-lang
<manveru>
:)
tallship joined #ruby-lang
<muzone>
ah there you are
enebo joined #ruby-lang
Phrogz joined #ruby-lang
<Phrogz>
Is there a more clever Enumerable method for doing this: v = nil; enum.find{ |o| v=transform(o) unless transform(o).nil? }; v
<Phrogz>
Basically "loop through the elements and map them to a new value, but stop as soon as you find one that has the proper mapping, _and get that mapped value back_. Note that enum.map{ ... }.compact.first is functionally equivalent, but doesn't shrot-circuit out.
<Phrogz>
SHROT!
<darix>
Phrogz: break
<Phrogz>
darix: dance
<mksm>
Phrogz, take_while perhaps
<Phrogz>
mksm: Nah, no good if you have to skip a few nils first.
<andrewvos>
rue: Yes, that's also another technique.
woollyams joined #ruby-lang
<andrewvos>
diegoviola: I feel I may have misunderstood your question?
<andrewvos>
As usual.
<Phrogz>
diegoviola: What do you mean by "increment it for one month"? When should this happen? When should it 'reset' (one month after what)?
Axsuul joined #ruby-lang
rolfb joined #ruby-lang
nofxx joined #ruby-lang
<vikoren>
diegoviola: redis with an expire set may work for you
twittard joined #ruby-lang
<diegoviola>
i have a counter and the counter gets a +1 every time a page is reloaded, i would like to keep the counter running for 1 month and then expire/reset the counter after 1 month
dRbiG joined #ruby-lang
havenn joined #ruby-lang
<vikoren>
diegoviola: do you want each view to expire, or just the counter?
Defusal joined #ruby-lang
Defusal joined #ruby-lang
workmad3 joined #ruby-lang
<vikoren>
diegoviola: "views in the last month" or "views this month"
Asher joined #ruby-lang
uberbrodt joined #ruby-lang
<diegoviola>
vikoren: views this month
<diegoviola>
vikoren: i'm storing the counter data in a databse, i simply want to reset the value from the database after 1 month
<diegoviola>
database*
<diegoviola>
i'm not sure how to handle the "1 month" thing, the time
<vikoren>
count_key = "#{year}:#{month}"; db.incr(count_key) # is how i would do it in redis
<diegoviola>
i'm using postgres
<rue>
If it's not a one-time thing, cron it
<vikoren>
the idea is the same…just append the year and month to the counter name and it will work with the side effect that you will also have a history of other months
<vikoren>
but if he creates then with the year and month as part of the name, it should work, yes?
<Asher>
sequences are just integers
<vikoren>
*them
<diegoviola>
they already have this sequence and they increment it on every page load, what i need to do is save the value of that sequence in another table after 1 month and then reset the sequence
<diegoviola>
i know how to save the value in another place, what i don't know is how to do it after X days
<diegoviola>
a cron job comes to my mind but i don't know...
gregmoreno joined #ruby-lang
malev joined #ruby-lang
<Asher>
just schedule a job once a day that deletes all records whose sequence is < the first sequence # from the given date
<erikh>
I call that work
<erikh>
it takes about 8-12 hours
workmad3 joined #ruby-lang
<rue>
Sounds a tedious job
<Asher>
calculating today - 30 days, selecting the dates that match with a limit of 1, using that result to select all sequences > than it?
<Asher>
8-12 hours a day definitely
robbrit left #ruby-lang
<erikh>
rue: eh, it's a living.
<rue>
I always wondered how cron worked. Now I know!
<Asher>
cron takes shifts
<andrewvos>
First you have to find a fresh cron... *That* takes at least three hours.
<erikh>
I like a smoke break now and again
<erikh>
I call it my clock skew break
<Asher>
i call it my bowl
<Asher>
and don't take breaks for it :P
burgestrand joined #ruby-lang
<andrewvos>
Hey how do I do an exact match on a string and get the index of the match?
<andrewvos>
But it could be any arbitrary string
<andrewvos>
So I need it to be escaped too if using regex
<diegoviola>
thanks
uberbrodt left #ruby-lang
<burgestrand>
andrewvos: =~ returns the index of where the match was found, Regexp.quote will help converting the string to a regex
<andrewvos>
burgestrand: Thanks!
<burgestrand>
:)
<apeiros_>
if you escape it anyway, just use String#index right away…
<andrewvos>
apeiros_: Hmm that will actuall do
<andrewvos>
actually*
<burgestrand>
I always forget String#index takes a string and not a single character
<andrewvos>
Wait, I actually want indices not a single index.
Manhose joined #ruby-lang
<apeiros_>
that's harder
arubis joined #ruby-lang
<apeiros_>
scan with $~ trickery
<burgestrand>
["A", "B", "C", "D"].move(from_index: 0, to_index: 2), assuming all elements are present after the operation and the array size does not change, what do think should be the result?
<apeiros_>
I think "to" is bad wording
<apeiros_>
either "before" or "after"
<burgestrand>
Hm, that’s a good though
<burgestrand>
…t!
<apeiros_>
with far too much thought, I'd expect the result to be ["B", "C", "A", "D"]
Jake232 joined #ruby-lang
<burgestrand>
So with a to_index: 1 would put it at index 1 after the operation is done?
<burgestrand>
I thought that made sense too, glad I’m not alone :d
<apeiros_>
yes, I'd expect the element to end up in the named index
<burgestrand>
Wrapping an API that has the same operation, but it essentially moved it to (to_index - 1) after the operation, only when moving it to a higher index than it previously had
<apeiros_>
that's the order you give
<apeiros_>
the primary order, so to say
<apeiros_>
anything else is secondary
<burgestrand>
Thanks for your input apeiros_, I’ll put it to good use
<apeiros_>
yw
<apeiros_>
glad I still make sense
<apeiros_>
<-- supertired
Wardrop joined #ruby-lang
<burgestrand>
Yeah, the before/after thought was useful, hadn’t thought of that at all either
arubis joined #ruby-lang
<apeiros_>
the problem with "to" is: what happens with the thing already occupying that space?
<burgestrand>
Exactly :)
woollyams joined #ruby-lang
<apeiros_>
and since the verb is 'move' and not 'swap' or even something else…
<burgestrand>
I’ve been fiddling with it too long, sometimes my brain just skips a few thought experiments
<apeiros_>
I tend to notice that I forget about occams razor far too often…
<rue>
I don't like moving everything down implicitly
<rue>
Especially considering a .move(0, 5) for example
<burgestrand>
Anyhow, if you’re curious to see what it’s for: http://goo.gl/RFT78 ; got full underlying API coverage, now it’s just to fix up the warts of my own API design
tijmencc joined #ruby-lang
<burgestrand>
Feels kind of similar to the [1, 2, 3][3, 1] thingy with ruby arrays, even though the operation itself is differnt
arubis joined #ruby-lang
<erikh>
I'm continually impressed this dwim
<erikh>
type[0, 1] = type[0, 1].upcase!
<apeiros_>
dwim?
<Mon_Ouie>
Fail if the character is already upper cased?
<Mon_Ouie>
apeiros_: does what I mean
<apeiros_>
ah
<erikh>
Mon_Ouie: it modifies the string, then returns the modified content, then assigns it to the first character
<erikh>
it's basically a ucfirst()
<erikh>
or capitalize I guess.
<apeiros_>
erikh: upcase! returns nil if nothing changes
<apeiros_>
as most core ruby bang methods with a non-bang twin
<erikh>
heh
<Mon_Ouie>
And String#[]= fails if you pass nil
<erikh>
I'm just surprised it doesn't create a new string
arubis joined #ruby-lang
<erikh>
ah, that's probably what happened.
<erikh>
tyvm interfriends
zmack joined #ruby-lang
<apeiros_>
probably in the top ten of bug sources…
outoftime joined #ruby-lang
<apeiros_>
number one is most likely still encodings. for some reason people don't seem to grasp those :-/
matti joined #ruby-lang
* Mon_Ouie
looks at shevy
gix joined #ruby-lang
<erikh>
he
<erikh>
done my turn with encodings
<erikh>
never again if I can manage it. ops has advantages.
<erikh>
nobody cares if daemons are localized
<apeiros_>
:D
<apeiros_>
my only issues with encodings: rails templates (gotta replace them with ones having `# encoding: utf-8` on top) and 3rd party libs (rails included :-S)
<apeiros_>
favourite bug in rails related to encoding so far: logger wouldn't log non-7bit ascii… not just that, no, it even crashed.
<apeiros_>
I wonder whether they actually fixed that (might have been in rails 2.3)
<erikh>
oh wow
<erikh>
was that Logger or somethign related to the syslog stack?
<erikh>
(I could totally see the latteR)
<apeiros_>
no, rails doing stupid re-encoding
<erikh>
yay
arubis` joined #ruby-lang
<erikh>
frameworks are so awesome guys
srbartlett joined #ruby-lang
<apeiros_>
only the NIH ones!
<rue>
erikh: Oh, you *think* no-one cares about i18n… give it a year
<rue>
In fact, I'm going to start a trolling campaign to make people think it's a good idea
<rue>
MUHAHAAA
<apeiros_>
I'd lend you my hobgoblin for that campaign
<erikh>
rue: heh
<erikh>
ßøøß
<jbwiv_>
guys, is clone defined in Kernel? I'm working on a rails project and trying to track down where clone is defined. method(:clone) tells me "#<Method: Vessel(Kernel)#clone>", while method(:clone).source_location returns nil
<jbwiv_>
also, rdoc info on clone doesn't show it being there
<Mon_Ouie>
Because RDoc lies
<zedUNDginger>
jbwiv_: method(:clone).owner
<Mon_Ouie>
It's documented in Object, but really implemented in Object
<Mon_Ouie>
And source_location is just nil because it's defined from C code
<jbwiv_>
Mon_Ouie, heh...ok. it does show it in object
<jbwiv_>
yes
<jbwiv_>
Mon_Ouie, did you mean it's documented in object but really implemented in kernel?
<Mon_Ouie>
Oops, yeah
arubis`` joined #ruby-lang
<jbwiv_>
Mon_Ouie, is it done and represented that way for a reason?
robotmay joined #ruby-lang
<rue>
Because they're FUCKING INSANE
jensn joined #ruby-lang
<rue>
*cough*
<vikoren>
rue: don't hold back man
<jbwiv_>
rue, that explains a lot. mind if I use that for my standard answer going forward? :-)
<rue>
By all means
thrcka joined #ruby-lang
arubis`` joined #ruby-lang
postmodern joined #ruby-lang
Pip joined #ruby-lang
savage- joined #ruby-lang
Pip joined #ruby-lang
arubis`` joined #ruby-lang
arooni-mobile joined #ruby-lang
aaronfeng joined #ruby-lang
looopy joined #ruby-lang
thrcka joined #ruby-lang
DRCALKIN joined #ruby-lang
amerine joined #ruby-lang
mark_locklear joined #ruby-lang
arubis`` joined #ruby-lang
arubis``` joined #ruby-lang
DRCALKIN joined #ruby-lang
takaokouji joined #ruby-lang
paul0` joined #ruby-lang
thrcka joined #ruby-lang
<andrewvos>
Does minitest autoload everything in lib??
<zedUNDginger>
andrewvos: i dont know sorry
<drbrain>
andrewvos: no
<steveklabnik>
that wouldnt be very mini
<andrewvos>
drbrain: For some reason I renamed a file but all my specs are still passing :|
<drbrain>
o_O
<andrewvos>
Well, I mean, my specs are still passing for some reason
<andrewvos>
Thought vim was getting clever
workmad3 joined #ruby-lang
<rue>
You renamed, didn't just :w to a new file?
<andrewvos>
rue: Nope
<andrewvos>
Weird. This is blowing my mind
<andrewvos>
Does minitest autoload the corresponding production file?
<andrewvos>
for example batman_spec loads batman in lib??
<rue>
No
<andrewvos>
Right this is blowing my mind
<andrewvos>
omfg
<andrewvos>
Right I'm quitting programming
<andrewvos>
This is it
<steveklabnik>
ol
<andrewvos>
I had my gem installed and wasn't running bundle exec :( :(
dreinull joined #ruby-lang
<jbwiv_>
is there a way to track down what method super will invoke via something like method()?
<zenspider>
what it'll invoke? it'll invoke the same named method via the superclass
<zenspider>
are you trying to find out where the code is? or?
<jbwiv_>
zenspider, yes, where the code is
<zenspider>
is there a reason why you want to know that?
<zedUNDginger>
jbwiv_: you can use a gem called method_locator that does that
<jbwiv_>
zenspider, yes, trying to trace some unexpected behavior in a library
<zenspider>
jbwiv_: use a debugger?
<jbwiv_>
zenspider, why yes, I do. I'm actually using pry at the moment
<zenspider>
pry isn't a debugger (yet?)
<zenspider>
set a breakpoint on the super call. step into it
<zedUNDginger>
jbwiv_: pry will tell you using --super
<zedUNDginger>
jbwiv_: show-method Class#method --super will tell u what method is called when u do 'super'
<zedUNDginger>
chain on as many --super to go up the ancestor chain and return the code for that method etc
<jbwiv_>
zedUNDginger, ok, thanks. I'll play with that
<jbwiv_>
zenspider, I was hoping to avoid actually having to step into the method to find it
<jbwiv_>
but that's an option
fra000 joined #ruby-lang
<jbwiv_>
zedUNDginger, this appears to be a bit unreliable. now necessarily --super, but show-method in general. For example, pry tells me I'm here (/vendor/plugins/state_machine/lib/state_machine/integrations/active_model.rb @ line 254 in StateMachine::Machine#write), but show-method StateMachine::Machine indicates write lives at /vendor/plugins/state_machine/lib/state_machine/machine.rb @ line 904
<jbwiv_>
s/now/not/
petercooper joined #ruby-lang
<zedUNDginger>
jbwiv_: can u tell me exactly what you typed? maybe gist the session?
<jbwiv_>
zedUNDginger, sure, one sec
<zedUNDginger>
because i dont see that it can be unreliable, we're just using source_location and friends
<jbwiv_>
note how adding --super says a superclass doesn't define that method as well
<zedUNDginger>
jbwiv_: can you just type: show-method
<zedUNDginger>
with no parameters
<zedUNDginger>
and gist the result
tvl joined #ruby-lang
<zedUNDginger>
btw u might want to join #pry
<zedUNDginger>
but it does seem like something spooky is going on
Carnage\ joined #ruby-lang
<chessguy>
ugh, i feel like i should know this, but am i missing some easy way to implement == for something like class Foo; def initialize(bar, baz); @bar == bar; @baz = @baz; end; end
<drbrain>
Foo = Struct.new :bar, :baz
<drbrain>
done
<rue>
Struct is the best thing ever
<chessguy>
drbrain: Struct makes those attr_readers, doesn't it? :)
<chessguy>
FAIL
<rue>
Everybody likes OpenStruct, but Struct is even more awesome
<drbrain>
chessguy: yes
<chessguy>
drbrain: so my brilliant implementation was different
<chessguy>
anyway the point was, determining equality based on more than one piece of state
<drbrain>
class Foo; protected :bar, :baz; end
<drbrain>
chessguy: easy fix!
<rue>
chessguy: Your original code has a few typos, it seems
<drbrain>
or, you can do that yourself and have:
<chessguy>
err, yes, sorry
<drbrain>
def ==(other) self.class === other and @bar == other.bar and @baz == other.baz
<drbrain>
end
looopy joined #ruby-lang
<chessguy>
oh, right!
<chessguy>
for some reason my mind went off on a Comparable tangent
<chessguy>
but Comparable doesn't return a boolean
<chessguy>
i forgot about just overriding ==
<rue>
chessguy: For that, implement #<=> :)
<drbrain>
Comparable is a module that provides ==, <, > <=, >=
<chessguy>
ok, my head's back on straight, sorry. carry on
<rue>
Though the semantics of the conditional might be a little trickier
looopy_ joined #ruby-lang
<andrewvos>
If i have some code how can I execute it line by line, but still keep state between each eval?
<andrewvos>
So.. for example
<zenspider>
hoe 2.12.4 released
<andrewvos>
["x = 1", "y = 2", "x + y"] should return 3 if that makes sense.
<crankharder>
is there some %() equivalent that interpolates?
<Mon_Ouie>
Yes, %()
deryl joined #ruby-lang
<Mon_Ouie>
%q(…) is the one that does *not* interpolate
<zenspider>
crankharder: also, see the quickref
<zenspider>
andrewvos: sounds like you want to write an interpreter
<zenspider>
that, or do the equivalent of mathematica's FoldList (fold but return each step) and then evaluate each one
<andrewvos>
zenspider: Well, I was hoping it would be a little easier than that.
<zenspider>
writing an interpreter isn't that hard, honestly...
<zenspider>
but I do understand. what are you actually trying to do?
<crankharder>
thanx
<andrewvos>
Well, I am writing a tool that reads through documentation and execute sthe code in the documentation. It then checks for #=> "value" type constructs and tries to confirm that the last code executed will equal that value.
<andrewvos>
zenspider: ^
<andrewvos>
zenspider: This might be a better explanation: github.com/AndrewVos/docu
<andrewvos>
zenspider: So now I want to support examples with multiple #=> assertions in one block
<zenspider>
andrewvos: this has been done (multiple times iirc)
<zenspider>
you can look at the xmp filter in irb for an example
<andrewvos>
zenspider: Hmm. Thanks will take a look
<zenspider>
there was one that specifically did # => comments
<zenspider>
and another that was a testing tool that made sure that the current code matched the output of the # => comment
<andrewvos>
zenspider: Yeah that's pretty much what I'm doing.
<zenspider>
I wish I could remember who did those or what they were called
<zenspider>
if you just want the functionality, hunt them down... if this is a learning exercise... carry on
<andrewvos>
zenspider: I'm digging through pry right now actually :)
<andrewvos>
zenspider: It's more a learning excercise.
<zenspider>
the problem with my fold solution is that rerunning the intermediate code can break shit
<andrewvos>
zenspider: I think that was my first approach. eval each line and keep the response.
<zenspider>
well... the FoldList thing is basically: [a,b,c].foldlist(&f) => [f(a), f(b, f(a)), f(c, f(b, f(a)))]
<zenspider>
so you'd have 1 line, 2 lines, 3 lines, etc, to eval