Skip to content

Instantly share code, notes, and snippets.

@jessekempf
Created July 29, 2013 19:45
Show Gist options
  • Save jessekempf/6107168 to your computer and use it in GitHub Desktop.
Save jessekempf/6107168 to your computer and use it in GitHub Desktop.
#Orig:
def self.unix_file_read(filename, &blk)
File.open(filename) do |file|
file.reduce([]) do |acc, entry|
entry.chomp!
if entry.strip.length == 0 || entry.start_with?('#')
next(acc)
end
acc << yield(entry.split(':'))
acc
end
end
end
#Parsed subject AST:
(defs
(self) :unix_file_read
(args
(arg :filename)
(blockarg :blk))
(block
(send
(const nil :File) :open
(lvar :filename))
(args
(arg :file))
(block
(send
(lvar :file) :reduce
(array))
(args
(arg :acc)
(arg :entry))
(begin
(send
(lvar :entry) :chomp!)
(if
(or
(send
(send
(send
(lvar :entry) :strip) :length) :==
(int 0))
(send
(lvar :entry) :start_with?
(str "#")))
(next
(begin
(lvar :acc))) nil)
(send
(lvar :acc) :<<
(yield
(send
(lvar :entry) :split
(str ":"))))
(lvar :acc)))))
#Unparsed source:
def self.unix_file_read(filename, &blk)
File.open(filename) do |file|
file.reduce([]) do |acc, entry|
entry.chomp!
if ((entry.strip.length == 0) || (entry.start_with?("#")))
next
end
acc << yield(entry.split(":"))
acc
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment