Ruby getObstacle Does Not Accept String Arguments

Issue #10 resolved
Muhsin King created an issue

Ruby's implementation of "getObstacle" from the Myro module does not seem to function properly. Running "getObstacle()" works fine, but "getObstacle(pos)" where pos is the string for the position of the obstacle you want ("left","right", or "center") then it gives the following error: Scribbler:0:in `getObstacle1': Cannot cast from source type to destination type. (System::InvalidCastException).

It does however respond if you use the integer arguments 0, 1, or 2. Presumably each of these represents left right or center. This is especially annoying as not only does Python accept the string arguments, but other Ruby functions do as well (getLight, for example). While getObstacle in ruby is not "broken" the way it is, it would add consistency to let it take strings as well.

Comments (6)

  1. Doug Blank

    That is probably because a Ruby string is something other than a real C# string. We should call obj.ToString() on anything in any method that wants a string. As a work-around, you can probably force the ruby string into a real string (prehaps with a call to the ToString method?)

  2. Doug Blank

    The first does not work, but the next ones do:

    Myro::getObstacle("left")
    Myro::getObstacle("left".ToString)
    Myro::getObstacle("right".ToString)
    

    Strangely, the methods that take a string work fine:

    Myro::getWindow("Myro Camera")
    
  3. Doug Blank

    I made changes to all of the robots, and Graphics so that Ruby should work better. Specifically, in a library I changed (value is string) and (value as string) and (string)value to something else, because those constructs don't work for Ruby strings. See 4a7ba59, and 5863f42 for details. If this works, please mark as resolved.

  4. Log in to comment