Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
!
I agree that Hash resulting from a proper solution to this kata would be an obscenity in production code, but I would still suggest people try to solve the kata in order to see how well they understand ruby. I tried, failed, and learned some things in the process (My thanks to @ineiti).
For the Ruby version:
module_function
to define module-level methods, notdef self.foo
. This plays nicer with bothinclude
andextend
.See my soln: http://www.codewars.com/kata/reviews/54f7910c20de9891c400004b/groups/5545e362647c1f924600007b
This kata needs a lot of work. To those struggling with this kata, it's honestly not worth your time. You're better off reading reading the
ostruct.rb
file that comes with the default Ruby interpreter to learn how this sort of thing should work.Hash
-like object that is indifferent to whether aSymbol
orString
is used as a key?method_missing
without callingsuper
.foo
without havingrespond_to?(:foo)
returntrue
.Hash
class already defined its ownmethod_misssing
? This is why libraries like hashie subclassHash
.I thought the same thing, but apparently starting with 0 is the "modern" form according to Wikipedia: http://en.wikipedia.org/wiki/Fibonacci_number
That being said Wolfram Alpha calls 0 the 0th Fibonacci. But meh.
And the usage of class variables. I'd say that's the most off.
You might be interested in a solution I posted: http://www.codewars.com/dojo/katas/reviews/52255487906b0c1733000452/groups/522cd249900801524d000063
It starts by implementing "exact arithmetic" in the field extension ℚ(𝜑) = {a + b𝜑 | a,b ∈ ℚ}, where ℚ are the rational numbers and 𝜑 is the golden ratio. Since
we can implement the "explicit formula" by implementing an algorithm for exponentiation in ℚ(𝜑) .
In the code, the representation works as follows
Why? It's not like you have to do every exercise.
This comment is hidden because it contains spoiler information about the solution
Just FYI, in Ruby you can do
instead of
This holds for any method which takes a block. The ampersand ("&") tells Ruby that this argument should serve as the block argument to the method and Ruby will then call
to_proc
on that object. In this case, Ruby will callSymbol#to_proc
since you're passing in a symbol, which works thus:This code isn't just unidiomatic, it's a little bit abusive. :)
You define a constant
CHILDS
and then modify it. Don't modify constants! Ruby lets you do this—don't ask me why—but it will at least throw a warning about the constant already being defined.Also, the plural of "child" is "children," which would be a better variable name.
The plural of "child" is "children," which would be the more appropriate variable name. Also, there's no reason to call
Array#map
here. You should just callArray#each
.There's no reason to call
Array#map
here. You should just callArray#each
.Idiomatically, there are three things off about your code:
Class
as input, one traditionally uses the variable nameklass
.do...end
, not{...}
.There's no reason to call
Array#map
here. You should just callArray#each
.Loading more items...