Skip to content

Instantly share code, notes, and snippets.

View freakhill's full-sized avatar

freakhill

  • tokyo
View GitHub Profile
@freakhill
freakhill / list_comprehension.rb
Last active December 17, 2015 06:19
having fun with "haskell like list comprehension in ruby" - https://gist.github.com/andkerosine/3356675
#!/usr/bin/env ruby-head
class VeryBasicObject < BasicObject
undef :==
undef :!=
undef :!
end
class Captured < VeryBasicObject
def method_missing meth, *args
require 'ripper'
require 'sourcify'
def lines(source)
Enumerator.new do |out|
source.split("\n")[1..-2].reduce("") do |buffer, line|
buffer << "\n#{line}"
Ripper.sexp_raw(buffer) ? (out << buffer) && "" : buffer
end
end