1 ## An Environment is used when executing commands. It provides short ways of accessing
2 ## information. For example:
3 ## * arg returns the string inserted after the command.
4 ## * name returns the name of the command
5 ## * rest2 returns the rest after the second argument.
7 ## env = Environment.new
9 ## code = "print(@string)"
10 ## env.run(code) ## prints the string "test"
16 string words rests name
17 word_number cursor_pos key
20 ## creates a new, empty environment.
26 ## before running code, it's a good idea to use the attribute accessors to set
27 ## environmental variables. these are:
38 rescue StandardError, ScriptError
43 ## returns the rest after the word n. methods with the name
44 ## restN with N from 0 to 15 are generated for more comfortable use.
46 ## It's a bit confusing where the counting begins, so I add an example:
48 ## if the command is "set filter salt & pepper"
49 ## * rest(0) => "filter salt & pepper"
50 ## * rest(1) => "salt & pepper"
51 ## * rest(2) => "& pepper"
53 (@rests.is_a?(Array) && @rests[n]) || ""
56 ## returns the nth space-seperated word. methods with the name
57 ## wordN for n from 0 to 15 are generated for more comfortable use.
60 ## It's a bit confusing where the counting begins, so I add an example:
62 ## if the command is "set filter salt & pepper"
64 ## * word(1) => "filter"
67 (@words.is_a?(Array) && @words[n]) || ""
70 ## arg is an alias for word: @words == @args, wordN == argN, word(N) == arg(N)
83 def word#{i}() word #{i} end
84 def rest#{i}() rest #{i} end
85 alias arg#{i} word#{i}