Skip to content

Instantly share code, notes, and snippets.

@asterite
Created October 12, 2014 23:52
Show Gist options
  • Select an option

  • Save asterite/296f09adca07b940f66d to your computer and use it in GitHub Desktop.

Select an option

Save asterite/296f09adca07b940f66d to your computer and use it in GitHub Desktop.
macro ruby_class(name)
_class = Ruby::Class.new({{name.id.stringify}})
{{yield}}
end
macro ruby_def(name, &block)
_class.def {{name}}, {{block.args.length}},
->(self : LibRuby::VALUE, {{*block.args.map { |arg| "#{arg} : LibRuby::VALUE".id } }}) do
{{yield}}
end
end
macro ruby_global_def(name, &block)
Ruby.global_def {{name}}, 0,
->({{*block.args.map { |arg| "#{arg} : LibRuby::VALUE".id } }}) do
{{yield}}
end
end
ruby_class Foo do
ruby_def "foo" do |a|
a = Ruby::Value.new(a)
"From Crystal!! #{a.to_s}".to_ruby
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment