# What does this mean?

**URL:** <https://www.ruby-forum.com/t/what-does-this-mean/191392>\
**Category:** Ruby\
**Created:** [July 11, 2010, 6:18pm UTC](https://www.ruby-forum.com/t/what-does-this-mean/191392 "2010-07-11T18:18:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 11, 2010, 6:18pm UTC](https://www.ruby-forum.com/t/what-does-this-mean/191392/1 "2010-07-11T18:18:58Z")

</div>

I’m just new to ruby, and want to ask about what this means (I got it  
from Why’s poignant guide to Ruby):  
[http://pastie.org/private/wndhyi2zshltqzwippqb3q](http://pastie.org/private/wndhyi2zshltqzwippqb3q)

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 12, 2010, 1:53am UTC](https://www.ruby-forum.com/t/what-does-this-mean/191392/2 "2010-07-12T01:53:44Z")

</div>

On Sun, Jul 11, 2010 at 5:19 PM, Abder-rahman Ali \<  
removed\_email\_address@domain.invalid\> wrote:

> ## I’m just new to ruby, and want to ask about what this means (I got it from Why’s poignant guide to Ruby): [http://pastie.org/private/wndhyi2zshltqzwippqb3q](http://pastie.org/private/wndhyi2zshltqzwippqb3q)
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

I think it would be OK to put that code in your email: it’s not very  
long.

z = :include?  
z = “a string”.respond\_to? z

Interactive Ruby can be very useful in finding out what’s going on.

irb  
z = :include?  
#=\> :include?  
z.class  
#=\> Symbol

So z is now a variable holding a reference to an object of class Symbol.

s = “a string”  
#=\> “a string”  
s.class  
#=\> String  
y = s.respond\_to? z  
#=\> true

respond\_to? is a method which asks an object whether it “recognizes” a  
method, and the argument to respond\_to? should be a symbol which is “the  
same” (I’m deliberately not being precise here - symbols were confusing  
to  
me when I first started using Ruby) as the method you want to see if the  
object will recognize, which here is named include?. In other words, is  
include? an instance method of the object. So this tells us that  
include? is  
a method which “a string” will respond to. Let’s try it.

s.include? “st”  
#=\> true  
s.include? “ts”  
#=\> false

For more details, we can look up this method here (and others might be  
able  
to explain how to use installed Ruby to get information on methods).

> **[Ruby-Doc.org: Documenting the Ruby Language](https://ruby-doc.org/)**
>
> Fast, searchable Ruby documentation for core and standard libraries. Plus, links to tutorials, guides, books, and related sites.

→ 1.8.6 Core

select class String  
[http://ruby-doc.org/core/classes/String.html](http://ruby-doc.org/core/classes/String.html)

find the include? method  
[http://ruby-doc.org/core/classes/String.html#M000811](http://ruby-doc.org/core/classes/String.html#M000811)

str.include? other\_str =\> true or false  
str.include? fixnum =\> true or false

Returns true if str contains the given string or character.  
“hello”.include? “lo” #=\> true  
“hello”.include? “ol” #=\> false  
“hello”.include? ?h #=\> true
