Ad
  • Custom User Avatar

    In the Ruby version, there doesn't seem to be a test case for any month with only 30 days being tested with a 31st date.

    i.e. [04-31] => should fail

    There's at least one accepted solution that fails to cover this case (example in my View Solution)

  • Custom User Avatar

    Any month with 30 days but that was attempted w/ a 31st date would pass in this.

    i.e. [09-31] => valid date

    Honestly kind of surprised that this test case was missed, especially in the extended cases...

  • Custom User Avatar

    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 object bar. You are probably accustomed to saying foo.bar(arg1, arg2) to call the bar method with some parameters.
    With send, you can call any method on an object by passing it in through send.
    I.e. foo.send(:bar, arg1, arg2)

    • the first parameter represents the method name (as a symbol), the second parameter represents any arguments you wish to pass into the bar method as parameters

    In 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. Saying 1 + 2 is actually the same as saying 1.+(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.

    • Fun fact: adding the splat to args (*args) specifies an argument list of variable length, and treats each index of the array as an individual parameter

    So 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!