Last active
May 15, 2019 14:35
-
-
Save brandondrew/3d45cd44e330dfd5ba2fcde147f37f92 to your computer and use it in GitHub Desktop.
examples of syntax for RubyDo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# goal: pass code to a Ruby interpreter running in background as a daemon | |
greeting = "hello" | |
source = "Ruby" | |
# desired syntax, which is impossible because the Crystal parser & lexer cannot ignore everything between `ruby do` & `end` | |
ruby do |greeting, source| | |
# put Ruby code here as just part of a normal block: | |
puts "#{greeting} from #{source}!" | |
end | |
# less pretty, but possible: | |
ruby(greeting, source, <<-RUBY | |
puts "#{greeting} from #{source}!" | |
RUBY) | |
# this would require the code-string being last after an arbitrary number of other arguments... | |
# maybe something like this would work...? | |
ruby do |greeting, source| | |
<<-RUBY | |
puts "#{greeting} from #{source}!" | |
RUBY | |
end | |
# can you pass a string as the block? I suppose so... | |
# the best option may be something like this: | |
ruby "./greet.rb", [greeting, source] | |
# just pass an array of variables to the ruby file | |
# the problem is that you lose the names of the variables: they're just ordered arguments... | |
# perhaps Crystal can iterate through the array, and create a string like this to eval with the Ruby file: | |
# greeting = "hello" | |
# source = "Ruby" | |
# then it might be possible to do things like this: | |
salutation = ruby "./greet.rb", {time: build}, [greeting, source] | |
salutation = ruby "./greet.rb", {time: run}, [greeting, source] # run time being the default | |
# build time might use a macro to replace the ruby call with the results... not sure if that's possible/sensible though |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment