Built-In Methods
287 words. Time to Read: About 2 minutes.This is just going to be a quick one. Recently, I was working on something (that I will discuss in an upcoming post) on an airplane. I was using Ruby. Obviously I’m not going to fork out five whole dollars for the onboard internet access, so I was roughing it. I came across an error.
Wham. undefined method contains? for String. Darnit! I had just gotten done programming in Python and I hadn’t programmed in Ruby for a little while, so I rewrote it.
NOPE. Unexpected keyword_in. Bah! I knew there was a method here, but I couldn’t for the life of me remember what it was. My first instinct was to immediately Google the Ruby String documentation, but – remember – no internet. Out of hope and despiration, with a quick prayer to the coding gods, I entered the following into the terminal:
There! Right at the front was what I needed. No Googling required. So the next time you reach for Google for a question, try asking your code first!
Author: Ryan Palo | Tags: ruby tricks |In case you’re interested, you can do the same thing in Python via
dir("potato").
Like my stuff? Have questions or feedback for me? Want to mentor me or get my help with something? Get in touch! To stay updated, subscribe via RSS