
Saved by Harold T. Harper
Learn to Program
Saved by Harold T. Harper
Methods That Take Procs When you pass a proc into a method, you can control when the proc is called, how many times it’s called, or even if it’s called at all.
Internal to a car object, though, much more would need to be going on; other things a car would need are a velocity, an orientation, and a position. These attributes would be modified by pressing on the gas or brake pedals and turning the wheel, of course, but the user wouldn’t be able to set the position directly (which would be like warping). You
... See moreWell, here’s the big secret behind the puts method: before puts tries to write out an object, it uses to_s to get the string version of that object. In fact, the s in puts stands for string; puts actually means put string.
You’ll notice the -0700 and -0800 in these times. That’s to account for the difference between the local time and Coordinated Universal Time, or UTC.
The variables are num (which is a parameter) and num_times_2. They both sit inside the method double_this. These (and all the variables you’ve seen so far) are local variables. This means they live inside the method, and they cannot leave. If you try to access them outside of the method, you’ll get an error:
JSON stands for “JavaScript Object Notation,” but it’s now used by almost every language (not just JavaScript) as a way to pass objects back and forth, especially over the Internet. JSON is nice because, even though it’s a way for computers to talk to each other, it’s still a human-readable (and human-editable) format.
As you can see from line 6, the capitalize method capitalizes only the first character, not the first letter. And as you’ve seen before, throughout all of these method calls, letters remains unchanged. I don’t mean to belabor the point, but it’s important to understand. Some methods do change the associated object, but you haven’t seen any yet, and
... See moreJSON is the most popular, most standard way of serializing the objects in your running program (encoding them as text), and deserializing them (turning the text back into objects).
Anyway, as you can see, reverse doesn’t change the original string; it simply makes a new backward version of it. That’s why var1 is still "stop" even after you called reverse on it.