---
title: "ruby 的 Enumerable 方法"
author: "夜鸣猪"
date: "2012-02-23T03:28:21Z"
tags: []
categories: ["编程语言"]
slug: "ruby-enumerable"
draft: false
lastmod: "2012-02-23T03:29:17Z"
id: 1418591
url: "https://hlee.iteye.com/blog/1418591"
---

grep
是===来判断是否存在符合条件的sub enumerable

```ruby

c = IO.constants
c.grep(/SEEK/)         #=> [:seek_set, :seek_cur, :seek_end]
res = c.grep(/SEEK/) {|v| IO.const_get(v) }
res                    #=> [0, 1, 2]

```


用来差方法很不错

```ruby

array.public_methods.grep(/^each_(.*)$/){ puts $1}
#index
#with_index
#entry
#slice
#cons
#with_object

```