irb

How do you pipe input and output to and from an interactive shell?

拥有回忆 提交于 2021-02-08 03:33:22
问题 I am trying to build an application that enables the user to interact with a command-line interactive shell, like IRB or Python. This means that I need to pipe user input into the shell and the shell's output back to the user. I was hoping this was going to be as easy as piping STDIN, STDOUT, and STDERR, but most shells seem to respond differently to STDIN input as opposed to direct keyboard input. For example, here is what happens when I pipe STDIN into python : $ python 1> py.out 2> py.err

How do you pipe input and output to and from an interactive shell?

别说谁变了你拦得住时间么 提交于 2021-02-08 03:31:13
问题 I am trying to build an application that enables the user to interact with a command-line interactive shell, like IRB or Python. This means that I need to pipe user input into the shell and the shell's output back to the user. I was hoping this was going to be as easy as piping STDIN, STDOUT, and STDERR, but most shells seem to respond differently to STDIN input as opposed to direct keyboard input. For example, here is what happens when I pipe STDIN into python : $ python 1> py.out 2> py.err

Ruby on Rails 之旅(四)—— 学习一下Ruby的基本语法(1)

强颜欢笑 提交于 2020-03-12 19:57:27
参考宝岛台湾Ruby社区的教程: http://ihower.tw/training/ruby-tutoral.html 感觉挺容易上手的。自己学着敲一便,有一个感性认识。语言是需要实践的学习过程的。 我们用irb这种交互式的工具来学习Ruby语言。 使用方法很简单,打开command窗口,输入irb,看到下面的提示符就表示成功打开了irb环境。 irb(main):001:0> 1)来一个世界上最简单的输出: irb(main):001:0> "hello world" => "hello world" 2) IRB 告诉我们最后的叙述执行结果。如果我们需要输出 “Hello World” 还需要多一行: irb(main):002:0> puts "hello world" hello world => nil puts 是 Ruby 的基本输出指令。但是什么是 => nil 呢? 那是那一行叙述的执行结果。 puts 总是回传 nil,nil 在 Ruby 中表示一个绝对的空值。 3)接下来把irb当计算机来用一用 irb(main):003:0> 3*23 => 69 irb(main):004:0> 3**2 => 9 irb(main):005:0> 3.sqrt NoMethodError: undefined method `sqrt' for 3:Fixnum

Why am I getting objects printed twice?

女生的网名这么多〃 提交于 2020-02-09 01:56:07
问题 When I am in irb or in rails and I create some iteration with each , I am getting the whole struct printed again in my terminal or inside the browser. Example: a = [1,2,3,4] a.each do |number| puts n end The result in irb terminal or inside the browser: 1 2 3 4 => [1,2,3,4] Why does this => [1,2,3,4] appear inside the browser? I can't create a single list in my page because the whole structure appears. 回答1: Every expression in Ruby returns a value; in irb , the value returned by the

Ruby: overriding the puts method

江枫思渺然 提交于 2020-01-13 09:32:34
问题 I've got a small program meant to be run in IRB. It ultimately outputs something that looks like an array, though technically isn't an array. (The class inherits from array.) The problem is, when I do an instance of this class, e.g. example = Awesome.new(1,2,3), and I write "puts example", IRB's default behavior is to put each element of example onto it's own line. So instead of [1,2,3] (which is what I want), IRB pops out this. 1 2 3 Is there a smart way to override the puts method for this

Ruby: overriding the puts method

a 夏天 提交于 2020-01-13 09:32:30
问题 I've got a small program meant to be run in IRB. It ultimately outputs something that looks like an array, though technically isn't an array. (The class inherits from array.) The problem is, when I do an instance of this class, e.g. example = Awesome.new(1,2,3), and I write "puts example", IRB's default behavior is to put each element of example onto it's own line. So instead of [1,2,3] (which is what I want), IRB pops out this. 1 2 3 Is there a smart way to override the puts method for this

Can not use variable in IRB after var = Watir::Browser.start 'url'

余生颓废 提交于 2020-01-03 12:02:25
问题 1.9.3-p327 :001 > require 'watir-webdriver' => true 1.9.3-p327 :002 > b = Watir::Browser.new Then firefox starts and I can do nothing. My IRB does not allow me to enter new commands. Tried different variations of browser initialization: b = Watir::Browser.new :opera b = Watir::Browser.new :firefox b = Watir::Browser.start 'url' There should appear something like: => #<OperaWatir::Browser:0x1496e57 @active_window=#<OperaWatir::Window:0x1eb1db2 @browser=#<OperaWatir::Browser:0x1496e57 ...>>,

Can not use variable in IRB after var = Watir::Browser.start 'url'

北战南征 提交于 2020-01-03 12:02:09
问题 1.9.3-p327 :001 > require 'watir-webdriver' => true 1.9.3-p327 :002 > b = Watir::Browser.new Then firefox starts and I can do nothing. My IRB does not allow me to enter new commands. Tried different variations of browser initialization: b = Watir::Browser.new :opera b = Watir::Browser.new :firefox b = Watir::Browser.start 'url' There should appear something like: => #<OperaWatir::Browser:0x1496e57 @active_window=#<OperaWatir::Window:0x1eb1db2 @browser=#<OperaWatir::Browser:0x1496e57 ...>>,

loading documents on IRB ruby

寵の児 提交于 2020-01-03 10:43:09
问题 I am trying to load a file into IRB. I have the file saved on my desktop titled "Ruby.rb" How do i load the file into IRB? I have tried using both, 'load "Ruby.rb"', 'load "Ruby"' and 'require "Ruby.rb". these documents are on my desktop, is there something requiring a path directory here? The path for the document is C:\Users\Jamal\desktop, am i meant to include this into the load "Ruby.rb" command? THanks 回答1: It depends on the version of Ruby you are using (1.8.x or 1.9.x). load and

Neither ruby and nor irb can load .rb file in current directory

依然范特西╮ 提交于 2019-12-31 08:44:16
问题 I'm having a really noob problem with importing files in Ruby. I'm making a Ruby app in Windows XP. All the class files for the app are in "C:/Documents/Prgm/Surveyor_Ruby/lib" . But when I require a file in another file, neither ruby nor irb can find the required file. The current directory's contents: C:\Documents\Prgm\Surveyor_Ruby\lib>dir Volume in drive C has no label. Volume Serial Number is AAAA-BBBB Directory of C:\Documents\Prgm\Surveyor_Ruby\lib 10/09/2010 06:32 PM <DIR> . 10/09