在ironruby控制台启动时加载程序集
我正在尝试加载一些默认程序集并使用ironruby 初始化一些变量,但我不知道从哪里开始。
我正在尝试创建类似于rails脚本/控制台的东西:您运行该脚本并获得一个控制台,其中所有rails类都可用,但使用了几个我自己的库。
问题是如何启动 IronRuby 控制台并默认加载(必需)一些程序集?
I'm trying to load some default assemblies and init some variables with ironruby, and I don't know where to start.
What I'm trying to create is something similar to rails script/console: you run that script and get a console where all rails Classes are available, but using a couple of my own library.
The question is how can I start an IronRuby console with some assemblies loaded (required) by default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望控制台预加载程序集,则必须使用 iirb 而不是 ir(实际上相同,但 UI 略有不同)。顺便说一句,这是 Rails 脚本/控制台使用的工具。
预加载程序集(或 ruby 模块)是通过 -r 开关完成的。例如,如果您想预加载“MyAssembly.dll”,请运行下一个命令:
如果您想执行几个不同的操作,例如加载多个程序集和初始化一些变量,我建议编写一个 rb 文件来完成所有这些操作。例如:
假设此代码文件名为“init.rb”,则按如下方式调用 iirb 工具:
然后您可以创建一个运行此命令行的批处理文件以方便使用。
PS,您也可以使用 --simple-prompt 开关来获得 ir.exe 控制台的相同“UI”:
If you want the console to preload assemblies, you'd have to use iirb and not ir (practically the same with a slightly different UI). This is, by the way, the tool that rails script/console uses.
Preloading assemblies (or ruby modules) is done via the -r switch. For example, if you'd like to preload "MyAssembly.dll", run the next command:
If you want to do several different operations like loading several assemblies and initializing some variables, I'd recommend writing an rb file that does all that. For example:
Assuming this code file is named "init.rb", then call the iirb tool as follows:
You can then create a batch file that runs this command line to ease its use.
P.S. you can use the --simple-prompt switch as well to get the same "UI" of the ir.exe console: