Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created February 26, 2013 17:51
Show Gist options
  • Select an option

  • Save michaelfeathers/5040502 to your computer and use it in GitHub Desktop.

Select an option

Save michaelfeathers/5040502 to your computer and use it in GitHub Desktop.
class Object
def ary?; is_a? Array; end
def str?; is_a? String; end
def nonempty_ary?
ary? && (not empty?)
end
end
def sexp_select sexp, symbols
(1..(max_nesting_level = 20)).map {|n| sexp.flatten(n)
.select(&:nonempty_ary?)
.select {|e| symbols.include? e[0] }}
.select(&:nonempty_ary?)
.flatten(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment