Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use fully qualified constant names #101

Open
wants to merge 1 commit into from

3 participants

@silkycove

Reference: http://ruby-dev.info/posts/43365 (fixed in 1.9.3)
It should be safe to use fully-qualified constant names in the block passed to instance_eval.

@deadprogram
Owner

It should be safe, but it does also make the code more "wordy" for the very young, plus the need to enter the extra colons. Are you sure this is such a good thing?

@silkycove

No, I am not sure. I agree that the code must be simple. The issue is 1.9.3 (and 1.8.7) causes NameError when we pass FORWARD and other constant names without the prefix (Sphero::) in the block. According to Bug# 4536: http://ruby-dev.info/posts/43365, the behaviour of 1.9.2 (no error) is incorrect and fixed in 1.9.3. My worry is if kids are confused by the difference between Ruby versions.
Defining FORWARD and others in the local scope of the example code might be an alternate solution.

@hunterboerner
Collaborator

I think that if one has a sphero and is able to connect it up then they are able to learn the great powers of ::

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2013
  1. @silkycove
This page is out of date. Refresh to see the latest.
View
8 public/help/en/robots/sphero_commands.html
@@ -56,19 +56,19 @@
<p>Pings Sphero to see if it is responding</p>
</div>
<div style="background: rgb(240, 248, 255); color: black" class="color">
- <h3>FORWARD</h3>
+ <h3>Sphero::FORWARD</h3>
<p>A constant value, same as 0</p>
</div>
<div style="background: rgb(240, 248, 255); color: black" class="color">
- <h3>BACKWARD</h3>
+ <h3>Sphero::BACKWARD</h3>
<p>A constant value, same as 180</p>
</div>
<div style="background: rgb(240, 248, 255); color: black" class="color">
- <h3>RIGHT</h3>
+ <h3>Sphero::RIGHT</h3>
<p>A constant value, same as 90</p>
</div>
<div style="background: rgb(240, 248, 255); color: black" class="color">
- <h3>LEFT</h3>
+ <h3>Sphero::LEFT</h3>
<p>A constant value, same as 270</p>
</div>
<p>There are more commands, but these are the most important. For more information, take a look at the Sphero gem documentation on Github.</p>
View
10 public/help/shared/robots/code1_1.rb
@@ -1,17 +1,17 @@
require 'sphero'
Sphero.start '/dev/tty.Sphero-YBW-RN-SPP' do
- roll 60, FORWARD
+ roll 60, Sphero::FORWARD
keep_going 3
- roll 60, RIGHT
+ roll 60, Sphero::RIGHT
keep_going 3
- roll 60, BACKWARD
+ roll 60, Sphero::BACKWARD
keep_going 3
- roll 60, LEFT
+ roll 60, Sphero::LEFT
keep_going 3
stop
-end
+end
Something went wrong with that request. Please try again.