2010-01-01から1年間の記事一覧

HighLine:HighLine#list の動作

>> require "highline/import" => true >> HighLine.new.list((1..10).to_a.map {|x| x.to_s}, :rows) => "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >> HighLine.new.list([], :inline) => "" >> HighLine.new.list(["1"], :inline) => "1" >> HighLine.new.list([…

HighLine:HighLine#color の挙動、中身

lib/highline/import.rb で delegate されていないので、HighLine.new せずに color では使用できない 普通は、say などの ERB の中で使うから メソッド単体で使用(記述)できるのか? メソッド内で呼ばれるのは、HighLine.use_color?, HighLine.using_color_…

HighLine:choose の挙動、中身

一部良く分かっていないが、全体の呼び出しは、(@menu.shell = false として) @menu = @question = Menu.new(&details) class Menu @menu.choices(*items) unless items.empty? @menu.answer_type = @menu.options @header = @menu.header @prompt = @menu.p…

HighLine:ask の挙動、中身

以下のように引数は、Question に引き渡される def ask( question, answer_type = String, &details ) # :yields: question @question ||= Question.new(question, answer_type, &details) gather への挙動 >> require "highline/import" => true >> ask("fo…

HighLine:agree

>> require "highline/import" => true >> agree("foo") foo y => true >> agree("foo") foo yes => true >> agree("foo") foo no => false >> agree("foo") foo n => false >> agree("foo") foo a Please enter "yes" or "no". foo yes => true >> agree("f…

HighLine:HighLine.using_color_scheme?

>> require "highline/import" => true >> HighLine.using_color_scheme? => false >> ft = HighLine::ColorScheme.new {|cs| cs[:headline] = [ :bold, :yellow, :on_black ]} => #<HighLine::ColorScheme:0xb79f290c @scheme={"headline"=>["\e[1m", "\e[33m", "\e[40m"]}> >> HighLine.color_scheme = ft => #</highline::colorscheme:0xb79f290c>

HighLine:HighLine.use_color?, .use_color=

>> require "highline/import" => true >> ft = HighLine::ColorScheme.new {|cs| cs[:headline] = [ :bold, :yellow, :on_black ]} => #<HighLine::ColorScheme:0xb79cbc44 @scheme={"headline"=>["\e[1m", "\e[33m", "\e[40m"]}> >> HighLine.color_scheme = ft => #</highline::colorscheme:0xb79cbc44>

HighLine:HighLine.track_eof?, .track_eof=

>> require "highline/import" => true >> HighLine.track_eof? => true >> ask("") ^D を入力 EOFError: The input stream is exhausted. from /usr/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/highline-1.6.1/lib/highline.rb:601:in `get_line' from /usr/…

HighLine:HighLine.new

>> require "highline/import" => true >> hl = HighLine.new => #<HighLine:0xb798e024 @gather=nil, @page_at=nil, @question=nil, @header=nil, @wrap_at=nil, @input=#<IO:0xb7d09578>, @output=#<IO:0xb7d09564>, @key=nil, @menu=nil, @prompt=nil, @answers=nil, @answer=nil> >> hl.say("hoge") hoge => nil >> hl …</io:0xb7d09564></highline:0xb798e024>

HighLine:HighLine.color_scheme, .color_scheme=

>> require "highline/import" => true >> HighLine.color_scheme => nil >> ft = HighLine::ColorScheme.new {|cs| cs[:headline] = [ :bold, :yellow, :on_black ]} => #<HighLine::ColorScheme:0xb7a1ab28 @scheme={"headline"=>["\e[1m", "\e[33m", "\e[40m"]}> >> HighLine.color_scheme => nil >> HighLine.col</highline::colorscheme:0xb7a1ab28>…

HighLine:Examples:Menus

まんま require "highline/import" choose do |menu| menu.prompt = "Please choose your favorite programming language? " menu.choice(:ruby) { say("Good choice!") } menu.choices(:python, :perl) { say("Not from around here, are you?") } end で、…

HighLine:Examples:ERb based output

まんま require "highline/import" say("This should be <%= color('bold', BOLD) %>!") で、 This should be bold!

HighLine:Examples:Reading passwords

まんま require "highline/import" p ask("Enter your password: ") { |q| q.echo = false } p ask("Enter your password: ") { |q| q.echo = "x" } で、 Enter your password: "aaa" Enter your password: xxx "aaa"

HighLine:Examples:Type conversion for answers

まんま require "highline/import" p ask("Birthday? ", Date).to_s p ask("Interests? (comma sep list) ", lambda { |str| str.split(/,\s*/) }) で、 Birthday? 2011-1-1 "2011-01-01" Interests? (comma sep list) foo, bar , baz ["foo", "bar ", "baz"]

HighLine:Examples:Validation

まんま require "highline/import" p ask("Age? ", Integer) { |q| q.in = 0..105 } p ask("Name? (last, first) ") { |q| q.validate = /\A\w+, ?\w+\Z/ } で、 Age? -1 Your answer isn't within the expected range (included in 0..105). ? 106 Your ans…

HighLine:Examples:Basic usage

まんま require "highline/import" p ask("Company? ") { |q| q.default = "none" } で、 Company? |none| "none"Company? |none| aaa "aaa"

mechanize:Mechanize::FileResponse#read_body

>> require 'mechanize/file_response' => true >> open("foo").read => "abc" >> x = Mechanize::FileResponse.new("foo") => #<Mechanize::FileResponse:0xb7bc78a4 @file_path="foo"> >> x.read_body >> x.read_body LocalJumpError: no block given from /usr/local/ruby-1.8.7/lib/ruby/gems/1.8/gems/mechani</mechanize::fileresponse:0xb7bc78a4>…

mechanize:Mechanize::FileResponse#get_fields

>> require 'mechanize/file_response' => true >> Mechanize::FileResponse.new("foo").get_fields("") => [] >> Mechanize::FileResponse.new("foo").get_fields("hoge") => []

mechanize:Mechanize::FileResponse#each_header

定義の中身がなくても大丈夫なのかな? >> require 'mechanize/file_response' => true >> Mechanize::FileResponse.new("foo").each_header => nil

mechanize:Mechanize::FileResponse#each

定義の中身がなくても大丈夫なのかな? >> require 'mechanize/file_response' => true >> Mechanize::FileResponse.new("foo_dir").each => nil

mechanize:Mechanize::FileResponse#content_length

>> require 'mechanize/file_response' => true >> Mechanize::FileResponse.new("foo").content_length => 3 >> Mechanize::FileResponse.new("foo_dir").content_length => 26

mechanize:Mechanize::FileResponse#code

>> require 'mechanize/file_response' => true >> Mechanize::FileResponse.new("foo").code => 200 >> Mechanize::FileResponse.new("hoge").code => 400 >> Mechanize::FileResponse.new("foo_dir").code => 200

mechanize:Mechanize::FileResponse#[]

>> require 'mechanize/file_response' => true >> x = Mechanize::FileResponse.new("foo") => #<Mechanize::FileResponse:0xb7c72ce0 @file_path="foo"> >> x['content-type'] => nil >> x = Mechanize::FileResponse.new("foo.html") => #<Mechanize::FileResponse:0xb7c651f8 @file_path="foo.html"> >> x['content-typ…</mechanize::fileresponse:0xb7c651f8></mechanize::fileresponse:0xb7c72ce0>

mechanize:Mechanize::FileResponse.new

>> require 'mechanize/file_response' => true >> open("foo").read => "abc" >> Mechanize::FileResponse.new("foo") => #<Mechanize::FileResponse:0xb7c1e99c @file_path="foo"></mechanize::fileresponse:0xb7c1e99c>

mechanize:Mechanize::FileSaver

>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb749417c ... >> agent.pluggable_parser.register_parser("image/png", Mechanize::FileSaver) => Mechanize::FileSaver >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png') => #</mechanize:0xb749417c>

mechanize:Mechanize::File#save, #save_as

>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb7413234 ... >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').class => Mechanize::File >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').save(</mechanize:0xb7413234>…

mechanize:Mechanize::File.new

grep しても File.new や FileSaver.new がないと思ったが、色々見てみたら分かったlib/mechanize/file.rb class File ... def initialize(uri=nil, response=nil, body=nil, code=nil) ... lib/mechanize/file_saver.rb class FileSaver < File ... def ini…

mechanize:Mechanize::File#filename

>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb74cc234 ... >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').class => Mechanize::File >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').filen</mechanize:0xb74cc234>…

mechanize:Mechanize::File#code

>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb73f417c ... >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').class => Mechanize::File >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').code </mechanize:0xb73f417c>…

mechanize:Mechanize::File#body

>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb74cf22c ... >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').class => Mechanize::File >> agent.get('http://www.google.co.jp/intl/en_com/images/srpr/logo1w.png').body </mechanize:0xb74cf22c>…