<Harzilein>
can you point out a good example for inheritance from array? i already have a MediaWikiLink object and now want to make collections from those and add a method that would mass-validate them
lcdhoffman has joined #ruby-lang
<bnagy>
class NotNeccessary < Array
<bnagy>
just do ary.all? {|mw| mw.valid?}
<Harzilein>
bnagy: no, the idea is that i have a more efficient way to validate multiple links (the mediawiki api allows calls with ?title=One|Two|Three
<dr_bob>
or ary.all? &:valid?
<bnagy>
imho anyway. Containers knowing how to validate their contents smells like poor OO to me
kedare has joined #ruby-lang
<dr_bob>
Harzilein: create a separate class and do not inherit Array
u_u has quit [Ping timeout: 248 seconds]
<apeiros_>
Harzilein: usually has-a relationships are to preferred over is-a.
<dr_bob>
my point
<Harzilein>
can you point me to any code that does similar things?
<Harzilein>
or should i just make a MediaWikiLink.mass_validate(mwl) class method?
virunga_ has joined #ruby-lang
virunga has quit [Quit: Sto andando via]
virunga_ has quit [Read error: Connection reset by peer]
virunga has joined #ruby-lang
<bnagy>
where mwl is an array or links?
<rue>
Composition > inheritance
<bnagy>
sounds reasonable to me
<bnagy>
s/or/of/
dhruvasagar has quit [Ping timeout: 276 seconds]
<bnagy>
semantically not quite perfect, but hey
<Harzilein>
bnagy: yes. i thought having a MediaWikiLinkCollection or something would help me later on though.
dhruvasagar has joined #ruby-lang
<rue>
Make one, then
<rue>
But don’t inherit Array.
<bnagy>
you can check out DelegateClass
<bnagy>
but tbh it sounds like excess fanciness
<Harzilein>
bnagy: at least i can be reasonably sure that i would not have found a name like delegateclass by myself
mwjcomputing2 has quit [Quit: Out....]
<Harzilein>
bnagy: i tried all kinds of array, collection, container searches on rubygems
<bnagy>
it's just a safer / nicer way to get a thing that works like a subclass
<bnagy>
but I prefer tying your meta stuff onto the class - File does that for example
<bnagy>
an array of Blahs should really just be exactly that, if you need meta methods they are better imho on Blah (the class)
lcdhoffman has quit [Quit: lcdhoffman]
<Harzilein>
okay, i'll write it like this and hope when i show the code someone can make it fancy ;)
<bnagy>
this area is kind of philosophy, though, so opinions probably differ widely in terms of exactly how to do it
<bnagy>
but I suspect that "don't subclass Array" is a widely held opinion
<workmad3>
bnagy: that's a widely held opinion, yes
<workmad3>
bnagy: I believe it's a widely held opinion because subclassing Array tends to lead to weirdness though (because a lot of Array is actually native implementation...)
burgestrand has quit [Quit: Leaving.]
kaiwren has quit [Ping timeout: 246 seconds]
<workmad3>
bnagy: I'm only operating on remembered hearsay there though, as I've never bothered trying it myself :)
dhruvasagar has quit [Ping timeout: 246 seconds]
<Harzilein>
shouldn't there be something where i can just plug in my MediaWikiLink class and get (though some naming convention perhaps) the mass_whatever class methods as methods on the collection/set/whatever?
<bnagy>
well whether or not it leads to problems, the philosophy is what rue said
<bnagy>
19:52 < rue> Composition > inheritance
<Harzilein>
i thought people make gems for such things all the time
kain has quit [Quit: exit]
dhruvasagar has joined #ruby-lang
virunga is now known as Brutus-
<bnagy>
Harzilein: you could, yeah, but why should a container know how to do that?
carloslopes has joined #ruby-lang
cha1tanya has quit [Quit: cha1tanya]
kaiwren has joined #ruby-lang
<bnagy>
you could dump them in a module and extend the instance you're using for example
<bnagy>
but that's not really all that much nicer than subclassing imho
<workmad3>
bnagy: ah, that one, yeah... that's a fairly common viewpoint, as composition is a weaker relationship than inheritance, it doesn't bring along as much meaning, so the viewpoint of 'Composition > Inheritance' comes from 'don't use the big hammer when you can use a small one'
<workmad3>
bnagy: but sometimes inheritance is the way to go... just don't jump straight to it (that's my view anyway)
burgestrand has joined #ruby-lang
<bnagy>
I use inheritance a lot - when I'm inheriting my own classes and they're small and I know exactly what everything does and I wrote them with inheritance in mind
<bnagy>
I just don't like "I want almost exactly a Hash but with some logic to calculate the cosine of the values in it"
u_u has joined #ruby-lang
robbyoconnor has quit [Ping timeout: 246 seconds]
dhruvasagar has quit [Ping timeout: 252 seconds]
dhruvasagar has joined #ruby-lang
Leeky is now known as Leeky_afk
<Harzilein>
hmm... when i want to write (as, bs) = ["a b", "a b"].map{|line| line.split(" ")}.something, what would something need to be?
<Brutus->
a method of Array class
<Harzilein>
heh
<Brutus->
instance method
<Harzilein>
i mean how i'd make [["a", "b"],["a", "b"]] become [["a", "a"], ["b", "b"]]
<jperry2>
I want to mock out the Vagrant::Environment and also test that when @vagrant.cli is called that it is called with the correct params
d3vic3 has quit [Ping timeout: 245 seconds]
chendo__ has joined #ruby-lang
kaiwren_ has joined #ruby-lang
kaiwren has quit [Ping timeout: 246 seconds]
kaiwren_ is now known as kaiwren
mztriz has joined #ruby-lang
<jperry2>
I know I could pass in a mocked object through the initialize but I'd rather not is there any way to mock out the new and the cli methods?
<jperry2>
or passing in a mocked object is the preferred approach?
kvirani has joined #ruby-lang
khaase_ has left #ruby-lang [#ruby-lang]
khaase has joined #ruby-lang
chendo__ has quit [Quit: Computer has gone to sleep.]
<workmad3>
jperry2: it's a valid form of dependency injection
<workmad3>
jperry2: much more so than shimming the new method :P
<jperry2>
@workmad3 - What approach would you take for the example I pasted
dous_ has joined #ruby-lang
kvirani has quit [Remote host closed the connection]
<jperry2>
would you pass the Vagrant object in to the TestRunner or initialize it in the test runner initialize method body
rolfb has quit [Quit: Leaving...]
<workmad3>
jperry2: I'd probably take a first step of extracting the vagrant environment creation out into a lazy-initialized accessor method
<workmad3>
jperry2: and only access it through the reader
andrewhl has joined #ruby-lang
bryancp has quit [Remote host closed the connection]
<workmad3>
jperry2: I'd ideally want to remove the construction of the environment from the TestRunner entirely eventually, but that would probably require more far-reaching changes, so would only be aiming for it in the long term
dous has quit [Ping timeout: 248 seconds]
<workmad3>
jperry2: but with just an accessor, you can at least stub out the accessor to inject your mock
<jperry2>
got it
<jperry2>
I'll try that
<jperry2>
@workmad3 - thx
lcdhoffman has joined #ruby-lang
slyphon has quit [Ping timeout: 245 seconds]
<jperry2>
@workmad3 - I can do something like this right?
<yorickpeterse>
whitequark: good thinking about storing the code
<whitequark>
it's mostly very nicely written, way above most of the code, but there are some nitpicks
<yorickpeterse>
Though I haven't checked if they're stored as references or cloned versions
<whitequark>
1) "@since"? seriously? you didn't have even a single release, you don't need to care about API compatibility
havenn has quit [Remote host closed the connection]
<whitequark>
i.e. it's good that you think about that stuff at all, but it's just noise at this point
<cout>
11 years of ruby programming and I'm going to use ActiveRecord for the first time today...
cha1tanya has left #ruby-lang [#ruby-lang]
<seanstickle>
cout: lucky you!
<whitequark>
2) 1.9 hashes look way better for the purpose you're using them
<cout>
seanstickle: lucky that I'm using it now or lucky that I've avoided it? :)
<yorickpeterse>
whitequark: @since can also be used to indicate when it was originally added. `git blame` easily gets overwritten
<seanstickle>
cout: whichever way makes you happier?
<whitequark>
yorickpeterse: and for what would you need that?
<cout>
seanstickle: I'm just happy that I'm using ruby
<seanstickle>
cout: :D
<yorickpeterse>
whitequark: heh, there's no practical benefit to it really, mostly a habit
<whitequark>
3) `return' is for control flow, not for returning values, really. it's just bad style.
<whitequark>
know your language well.
<seanstickle>
Never use return.
<yorickpeterse>
I'd disagree on that one, I'm not a big fan of just a value at the end of a method
<seanstickle>
Of course, some people have differing opinions on that
<whitequark>
apart from that, it's really clean and nicely writed code.
<whitequark>
yorickpeterse: there's a problem with that.
<yorickpeterse>
oh?
<whitequark>
yorickpeterse: "value at the end of method" is not a quirk or a shortcut. it's a way Ruby control flow constructs work. if, case, whatever you see follows this convention
t4nkd has joined #ruby-lang
<whitequark>
so by writing "return" you're not making something unobvious explicit
<yorickpeterse>
Is there a practical benefit to not using `return` at the end of a method?
<yorickpeterse>
Besides just "It looks nicer" or something similar
<whitequark>
it _is_ obvious because it's the basic way of how Ruby works
<workmad3>
yorickpeterse: some benchmarks have actually shown explicit returns to be slower
<whitequark>
workmad3: bullshit
<yorickpeterse>
hmm
<whitequark>
the generated bytecode is identical
<whitequark>
you can check it if you want
<workmad3>
whitequark: hey, I didn't say they were valid benchmarks :P
<yorickpeterse>
I suppose it's a habit I have from writing JS/PHP all day
<workmad3>
whitequark: just that some had...
<yorickpeterse>
in which `return` is explicitly required
<whitequark>
microbenchmarks aren't useful anyway
<seanstickle>
It doesn't really matter. This is the idiom.
<seanstickle>
You want to vary from the idiom, that's up to you.
<whitequark>
yorickpeterse: as per practical benefit... there isn't any immediate practical benefit from any of the coding style considerations
<seanstickle>
But it's going to get under people's feathers.
<kitallis>
can I override the splat * on Array?
<whitequark>
you can omit indenting whatsoever, your code won't work worse.
<yorickpeterse>
whitequark: I'll take a look at it, the hash syntax is something I still have to decide about as well
<whitequark>
kitallis: no.
<yorickpeterse>
Other than that, thanks :)
<whitequark>
yorickpeterse: you're welcome
<whitequark>
kitallis: but you can subclass Array and reimplement to_a. I think that should work, never tested it through
<whitequark>
and that's pretty evil
<kitallis>
whitequark, overriding to_a on non-Arrays works
<whitequark>
kitallis: afaik MRI does an explicit check for Array for splats
<whitequark>
I'll check the source in a few minutes
<yorickpeterse>
yes. I pull out the source code and run `@lines = code.lines.to_a`
seanstickle has left #ruby-lang [#ruby-lang]
<whitequark>
ah, I misread your gist. I thought you store the code for just the subexpression in that array
<yorickpeterse>
No, it's stored when the parser is initialized
<whitequark>
then it's not as leaky but is also not nearly as useful
<whitequark>
because I dunno what I need the code for entire line in the OperatorToken for.
<whitequark>
also, consider that you can have \ at the end of line
<whitequark>
or just have + and a line terminator
<yorickpeterse>
It's useful for checking, say, indentation. Other than that I agree that it's somewhat useless in the current state
<whitequark>
you cannot reliably describe code positions with just the line number
rutkla has quit [Ping timeout: 244 seconds]
<whitequark>
I represent it with four values: line/character of token begin and line/character of token end
bytephilia has joined #ruby-lang
<whitequark>
(not for Ruby, but for a templating language I've just developed)
<yorickpeterse>
Hmm
<whitequark>
for that language, it's enough. for Ruby, it may be even more complicated
<yorickpeterse>
The annoying bit about Ripper is that sometimes the line/column numbers are set to the end position and sometimes to the start position.
<whitequark>
i.e. heredocs cannot be represented with that set of four values.
<yorickpeterse>
But either way that sounds like a better solution
carlos_ribeiro has joined #ruby-lang
<whitequark>
a heredoc has the 'content' part and the 'reference' part (<<'HEREDOC', that is)
<whitequark>
I'm pretty sure there are other examples, so I advise you to allow for multiple intervals in your AST nodes.
<whitequark>
it'll pay off.
<whitequark>
google how clang reports syntax errors, or just check it yourself. it's awesome and incredibly useful
<yorickpeterse>
will do
<yorickpeterse>
Hmm
justinseiter has quit [Ping timeout: 276 seconds]
havenn has joined #ruby-lang
kaiwren_ has joined #ruby-lang
<vbatts>
drbrain: zlib ping (since i saw you last worked on streaming)
gnufied1 has joined #ruby-lang
kitallis has quit [Ping timeout: 248 seconds]
<vbatts>
ah, hrm
kitallis has joined #ruby-lang
kaiwren has quit [Ping timeout: 252 seconds]
kaiwren_ is now known as kaiwren
kaiwren has quit [Read error: Connection reset by peer]
kaiwren_ has joined #ruby-lang
<vbatts>
drbrain: i think i just answered my own question :-\
coryf has joined #ruby-lang
rodj has quit [Quit: Page closed]
shevy has quit [Ping timeout: 246 seconds]
havenn has quit [Remote host closed the connection]
butchanton has joined #ruby-lang
mytrile has quit [Remote host closed the connection]
apeiros_ has quit [Remote host closed the connection]
bglusman has quit [Remote host closed the connection]
zmack_ has quit [Remote host closed the connection]
andrewhl has quit [Remote host closed the connection]
andrewhl has joined #ruby-lang
andrewhl has quit [Read error: Connection reset by peer]
andrewhl has joined #ruby-lang
savage- has quit [Remote host closed the connection]
Hakon has quit [Quit: Leaving...]
erpuds has joined #ruby-lang
shevy2 has joined #ruby-lang
vmoravec has quit [Quit: Leaving]
kaiwren_ has quit [Quit: kaiwren_]
dr_bob has quit []
<cout>
what's the best channel to ask ActiveSupport questions?
kitallis has quit [Quit: Computer has gone to sleep.]
apeiros_ has joined #ruby-lang
erpuds has quit [Quit: erpuds]
robotmay has quit [Remote host closed the connection]
alessio has quit [Remote host closed the connection]
joast has quit [Quit: Leaving.]
jrafanie has quit [Read error: Connection reset by peer]
carloslopes has quit [Quit: Leaving.]
jrafanie has joined #ruby-lang
savage- has joined #ruby-lang
<yorickpeterse>
cout: Probably #rails but I'm not entirely sure about that
gnufied1 has quit [Quit: Leaving.]
<whitequark>
#rails definitely
t0h has quit [Read error: Operation timed out]
<telemachus>
maybe #rails-bridge
<telemachus>
Thought it was friendlier/less crowded than #rails - but maybe not.
<apeiros_>
whitequark: #rails definitively not :)
<apeiros_>
#rails != #rubyonrails
<apeiros_>
#ror == #rubyonrails, though
<telemachus>
apeiros_: oh, k
<telemachus>
which one is bad?
chimkan has joined #ruby-lang
<jperry2>
anyone know how to mock a method that receives two calls with two different params?
<jperry2>
using mocha
<telemachus>
Let me put it another way: I've been in #rails-bridge. It was helpful, as I recall. :)
t0h has joined #ruby-lang
<apeiros_>
telemachus: join both and look at the user-count :-p
chimkan has quit [Read error: Connection reset by peer]
enroxorz is now known as bodie
<telemachus>
apeiros_: I don't want any rails help right now, lol. Just wanted to recall which one was filled with trolls for future reference (if someone else asked).
bodie is now known as OmarLittle
<apeiros_>
telemachus: hu?
<apeiros_>
you're on irc dude
<apeiros_>
which channel *isn't* full of trolls? :D
<OmarLittle>
apeiros_: the one you create and +i yourself
<telemachus>
apeiros_: Well, sure, but also no.
<telemachus>
Example: I like it here fine. Pretty good overall, in my experience.
<erikh>
OmarLittle: omar's comin'
<apeiros_>
OmarLittle: that'd mean 100% of its users are trolls :-p
* OmarLittle
walks to get cereal
<telemachus>
erikh: omar walkin'
<telemachus>
dropping that package out the window
* telemachus
needs to watch wire again...
<OmarLittle>
im making my fiancee watch it now
<OmarLittle>
she is loving it
<erikh>
i've been watching it again as I put it on the plex
<erikh>
got the box set a while back but I ditched my DVD player
butchanton has quit [Quit: Leaving.]
<erikh>
related, roku+plex == total win
<shevy>
OmarLittle can I watch your fiancee
<OmarLittle>
i need to do that soon. actually, gonna convert my box to a plex machine as soon as i get my gaming rig.
<erikh>
see, our best troll is shevy
<OmarLittle>
shevy: oh, fo sho. no doubt
<erikh>
well that and the detroit/madonna guy
<shevy>
I am just opportunistic
<erikh>
who probably just is shevy
<OmarLittle>
he does it right
<OmarLittle>
it's all in the game
<shevy>
nah, I wouldn't know what to do with detroit...
itsmeduncan has joined #ruby-lang
diegoviola has joined #ruby-lang
dhruvasagar has joined #ruby-lang
Defusal has quit [Read error: Connection reset by peer]
verbad has joined #ruby-lang
joast has joined #ruby-lang
banisterfiend is now known as banister`dreamla
banister`dreamla is now known as banisterfiend
verbad has quit [Client Quit]
erpuds has joined #ruby-lang
butchanton has joined #ruby-lang
butchanton has quit [Client Quit]
butchanton has joined #ruby-lang
Leeky_afk is now known as Leeky
butchanton has quit [Remote host closed the connection]
sgonyea has quit [Quit: sgonyea]
JohnBat26 has quit [Read error: Operation timed out]
bytephilia has quit [Remote host closed the connection]
w0lverine has joined #ruby-lang
mrsolo has joined #ruby-lang
towski has joined #ruby-lang
zmack has joined #ruby-lang
carloslopes has joined #ruby-lang
mztriz has quit [Quit: Leaving]
butchanton has joined #ruby-lang
carloslopes has quit [Client Quit]
carloslopes has joined #ruby-lang
butchanton has quit [Remote host closed the connection]
wallerdev has joined #ruby-lang
butchanton has joined #ruby-lang
dc5ala has joined #ruby-lang
butchanton has quit [Remote host closed the connection]
butchanton has joined #ruby-lang
runeb has quit [Remote host closed the connection]
butchanton has quit [Remote host closed the connection]
cdt has quit [Quit: Ex-Chat]
macmartine has joined #ruby-lang
erpuds has quit [Quit: erpuds]
brdude has joined #ruby-lang
havenn has joined #ruby-lang
<apeiros_>
hm, would be nice if each_cons accepted a step-width
chrismcg is now known as zz_chrismcg
<drbrain>
vbatts: ...
<apeiros_>
so instead of `@entities.each_slice(2).each_cons(2).all? { |(a,_),(b,_)|`, I could write `@entities.each_cons(2,2).all? { |a,_,b,_|`
FiXato has quit [Read error: Connection reset by peer]
naz has quit [Read error: Connection reset by peer]
brdude has quit [Ping timeout: 248 seconds]
naz has joined #ruby-lang
FiXato has joined #ruby-lang
hynkle has joined #ruby-lang
FiXato has quit [Remote host closed the connection]
FiXato has joined #ruby-lang
headius has quit [Quit: headius]
havenn has quit [Remote host closed the connection]
digitaldarwin has joined #ruby-lang
<digitaldarwin>
pastie: hi!
<digitaldarwin>
hmmm
<digitaldarwin>
does pastie not work in here?
<drbrain>
digitaldarwin: use a paste script, it'll save you an entire step
<Mon_Ouie>
It's not been here for years — literally
coryf has quit [Remote host closed the connection]
bryancp has quit [Remote host closed the connection]
jrafanie has joined #ruby-lang
itsmeduncan has quit [Quit: itsmeduncan]
TorpedoSkyline has quit [Quit: Computer has gone to sleep.]
banisterfiend has joined #ruby-lang
<zenspider>
flay 2.0.0.b1 released!
apeiros_ has quit [Remote host closed the connection]
<zenspider>
hoe 3.0.7 released
andrewhl_ has quit [Remote host closed the connection]
<zenspider>
flog 3.0.0.b2 released!
RickHull has joined #ruby-lang
macmartine has quit [Quit: Computer has gone to sleep.]
<banisterfiend>
zenspider: you're a busy boi
VegetableSpoon has quit [Quit: Leaving]
<zenspider>
I ignored omnifocus last week while I was working on my talk... huge backlog
<zenspider>
I'm caught up on the releases
<zenspider>
just barely tho
<banisterfiend>
cool
sailias has joined #ruby-lang
<erikh>
anyone know if arel orders its where clauses according to complexity?
<zenspider>
don't really feel motivated to work on the known issues in ruby_parser right now...
<zenspider>
should find something to play with instead
<erikh>
like unwinding a stack or something
<erikh>
zenspider: rust-lang.org
kvirani has joined #ruby-lang
tenderlove has joined #ruby-lang
<zenspider>
hrm...
<zenspider>
I don't really like/do type-systems
kvirani has quit [Remote host closed the connection]
<tenderlove>
omg
gsav has quit [Ping timeout: 256 seconds]
<erikh>
tenderlove: hey, we're trying to sort out a query that is arel driven and seems to order its where clauses based on the complexity of the clause (e.g. where foo = 0 and x between y and z)... trying to target a mysql index. is there a way to force a certain ordering?
<zenspider>
why would the ordering matter?
<erikh>
because it's mysql
<zenspider>
shouldn't the db be doing its own optimizations anyhow?
<tenderlove>
erikh: not really. You *could* mutate the where clauses on the Relation object
<tenderlove>
but there's no AR API for it
<erikh>
ok, good to know. thanks.
<tenderlove>
and also it might change in the future
<tenderlove>
erikh: just look at Relation#where_values (IIRC)
<erikh>
awesome. thank you.
<drbrain>
zenspider: you have to order your query specially to get mysql to use the proper index… and other silly things
<GeekOnCoffee>
:( I thought mysql was smarter than that
<zenspider>
GeekOnCoffee: fool. :P
<drbrain>
GeekOnCoffee: it depends heavily on the query and indexes available
andrewhl has joined #ruby-lang
<GeekOnCoffee>
I spent way too long working with legacy schemas in http://www.progress.com/en/index.html and MsSQL where simply getting AR generating queries it would accept was a blessing
hynkle has quit [Quit: Computer has gone to sleep.]
<GeekOnCoffee>
I wonder, is there an easy way to tell MySQL which index to use, and would manually specifying the index be a simpler solution to erikh's problem?