DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

Daniel Schierbeck's picture

Unregistered

Feeds

aliases

  • Daniel Schierbeck

Daniel Schierbeck

5 months ago

in git ready » restoring lost commits on git ready: daily git tips
Instead of `git merge 7c61179`, you could simply use `git reset --hard 7c61179`, which in my opinion is more intuitive.
1 reply
qrush Yes, that's helpful as well, but I wonder if it'll work just as fine with multiple lost commits.

7 months ago

in Thinking out of the Box with Enumerable#inject on Ruby Advent 2008
You've repeated a common mistake regarding `#inject` -- that you are supposed to assign to the accumulator variable. Instead, do this:

sum = (1..10).inject(0) {|a, i| a+ i }

For each iteration, the value of `a` will be the value of the last call to the block, or, if it's the first iteration, the default value. The only reason assignment works is because `a += i` is an expression which returns `a + i`.
1 reply
pet3r > The only reason assignment works is because `a += i` is an expression which returns `a + i

Yeah, I know, that's why I used it - it might be just me, but I find it more natural like this while I don't feel like I am doing a mistake in this case (not talking about inject()ing like this in general, jut about this case)

8 months ago

in Testing Private Methods on Virtuous Code
Or the `slugify` method could be turned into a function, since it isn't really relevant to the `BlogPost` instance.
1 reply
avdi's picture
avdi Ruby doesn't really support the notion of free functions (it kind of fakes it, but in a way I prefer not to take advantage of in anything but quick one-off scripts). It could be a class-level method, I suppose. I still prefer the class approach, because then if you decide to mock the slugification out you're not mocking methods on the class under test.
Returning? Login