# I don't know:&:empty?

**URL:** <https://www.ruby-forum.com/t/i-dont-know-empty/186908>\
**Category:** Ruby\
**Created:** [April 14, 2010, 7:18am UTC](https://www.ruby-forum.com/t/i-dont-know-empty/186908 "2010-04-14T07:18:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [April 14, 2010, 7:18am UTC](https://www.ruby-forum.com/t/i-dont-know-empty/186908/1 "2010-04-14T07:18:20Z")

</div>

there is one commade:  
‘[“ffgh”]78’.split(/[|]/).reject(&:empty?)  
i can get two character: “ffgh” 78  
but i don’t know what is the meaning of :  
&:empty?  
1\what is :  
2\what is &:  
think you for advance.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [April 14, 2010, 7:46am UTC](https://www.ruby-forum.com/t/i-dont-know-empty/186908/2 "2010-04-14T07:46:45Z")

</div>

On Wed, Apr 14, 2010 at 12:18 AM, Pen T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

:empty? is a symbol, & converts it to a proc. This is the same as saying  
‘[“ffgh”]78’.split(/[|]/).reject { |str| str.empty? }

It’s purpose seems to be to remove the empty string from splitting on  
the  
first character (that first bracket).

p ‘[“ffgh”]78’.split(/[|]/)  
p ‘[“ffgh”]78’.split(/[|]/).reject { |str| str.empty? }  
p ‘[“ffgh”]78’.split(/[|]/).reject(&:empty?)

To better illustrate, lets implement something similar. Here is an  
example,  
where we do the same thing with a String as you do with the Symbol. (It  
is a  
hypothetical implementation, I don’t know how Ruby actually has it  
implemented.)

puts RUBY\_VERSION # for me: 1.9.1

counts = %w(first second)  
begin  
puts “#{counts.shift} time trying &‘empty?’”  
p ‘[“ffgh”]78’.split(/[|]/).reject(&‘empty?’)  
rescue  
puts “rescued because String doesn’t have a to\_proc method”  
class String  
def to\_proc  
lambda { |obj| obj.send self }  
end  
end  
puts “If this was successful, then you should see the same results for  
&‘empty?’ as &:empty?”  
retry  
end

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [April 14, 2010, 10:45am UTC](https://www.ruby-forum.com/t/i-dont-know-empty/186908/3 "2010-04-14T10:45:26Z")

</div>

Pen T. wrote:

> 1\what is :

Identifies the start of a symbol literal. That is, :empty? is a symbol  
(in this case, being used as the name of a method)

> 2\what is &:

[http://pragdave.pragprog.com/pragdave/2005/11/symbolto\_proc.html](http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html)
