Skip to content

Instantly share code, notes, and snippets.

@aeden
Last active May 16, 2016 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeden/47e8e8201694c03174c752a64ae3f157 to your computer and use it in GitHub Desktop.
Save aeden/47e8e8201694c03174c752a64ae3f157 to your computer and use it in GitHub Desktop.
Ruby script to convert erlang define to functions, for access from Elixir
#!/usr/bin/env ruby
# Converts all Erlang macro defines to Erlang functions.
# This is useful if you want to access those values from Elixir.
#
# If the defines are in an .hrl file, you should copy all of the
# defines into a .erl file first and then run the script on that
# .erl file. The script will copy the .erl file to .erl.old and
# then will overwrite the existing .erl file.
require 'fileutils'
ARGV.each do |name|
buffer = []
FileUtils.cp(name, name + ".old")
open(name) do |f|
f.readlines.each do |line|
if line =~ /-define\((.*),/
buffer << "#{$1.downcase}() -> ?#{$1}.\n"
else
buffer << line
end
end
end
open(name, 'w') do |f|
f << buffer.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment