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.
See corrected solution
Not
A-z
but[A-Za-z]
or[a-z]/i
The only problem I have with this is, dynamic method definitions make being able to grep the code base for method definitions while refactoring hard.
This could be improved by defaulting
args
to[ :to_f ]
, thus eliminating the need for the ternary operator.nice solution! but it doesn't filter "#120398".
needs some tests cases for this type and extend your solution
I'll give you a quick explanation here, look it up to get further information (StackOverflow, ruby docs, etc.)
Anyways, say you have an object
foo
and a method associated with that objectbar
. You are probably accustomed to sayingfoo.bar(arg1, arg2)
to call thebar
method with some parameters.With
send
, you can call any method on an object by passing it in throughsend
.I.e.
foo.send(:bar, arg1, arg2)
bar
method as parametersIn this context,
send
allows us to dynamically call a method of a variable name on an object of a variable name. Without it, we would probably end up having to define individual methods for each number.So for example
n
is an instance/object of the Integer class. That means it has methods we can call on it. Saying1 + 2
is actually the same as saying1.+(2)
To tie into the operands, when we say
n.send(*args)
,args
will actually initially represent the array returned by the similar dynamic method creation we are doing with the operands.*args
) specifies an argument list of variable length, and treats each index of the array as an individual parameterSo by doing so, we finally have something like this:
->
six(times(two()))
->
six(times(2))
->
six([*, 2])
->
6.send(*, 2)
->
6.*(2)
=>
12
I got a bit carried away but I hope that helps explain things for you!
Can anyone explain n.send ?
Also, the operands? How does this all work?
Probably it passes these tests, however I'd not use it in live, for example:
for post = "Hello #World!" it returns [], obviously that words might be splitted with commas and other punctuation marks not only spaces.
or /A-z/
not the best if it doesn't match the requirements
but i'm sure this guy could easily make it match
to fix it, would one replace the \w+ pattern with /[[:alpha:]]/?
also #_ =P
Nevertheless, I just learned a new enum =D.
It's an incorrect solution.
It matches #123 while the description clearly forbids it.
Indeed. Who needs floating point math? ;)
Best solution.