Ad
  • Custom User Avatar
  • Custom User Avatar

    Not A-z but [A-Za-z] or [a-z]/i

  • Default User Avatar

    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.

  • Custom User Avatar

    This could be improved by defaulting args to [ :to_f ], thus eliminating the need for the ternary operator.

  • Custom User Avatar

    nice solution! but it doesn't filter "#120398".
    needs some tests cases for this type and extend your solution

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

  • Custom User Avatar

    Can anyone explain n.send ?

    Also, the operands? How does this all work?

  • Default User Avatar

    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.

  • Custom User Avatar
  • Custom User Avatar

    not the best if it doesn't match the requirements
    but i'm sure this guy could easily make it match

  • Custom User Avatar

    to fix it, would one replace the \w+ pattern with /[[:alpha:]]/?

  • Custom User Avatar

    also #_ =P

    Nevertheless, I just learned a new enum =D.

  • Default User Avatar

    It's an incorrect solution.
    It matches #123 while the description clearly forbids it.

  • Default User Avatar

    Indeed. Who needs floating point math? ;)

  • Custom User Avatar

    Best solution.