1. Rubyについて
Ruby in Twenty Minutes
irbを使ってみよう
irb
とtypeしてirbを起動しよう。インタラクティブなrubyが起動します。
https://www.ruby-lang.org/en/documentation/quickstart/
これをやってみたあとに下記の演習をやってください。
irb(main):001:0> 23 + 27
=> 50
irb(main):002:0> 50 - 23
=> 27
irb(main):003:0> 10 * 5
=> 50
irb(main):004:0> 10**5
=> 100000
irb(main):006:0> x = 1
=> 1
irb(main):007:0> x + 59
=> 60
irb(main):005:0> 50 / 5
=> 10
irb(main):008:0> hi = "Hello, Mac!"
=> "Hello, Mac!"
You can also invoke a single program with irb. After running the program, irb exits. Let's call our hello.rb program −
$ irb hello.rb
hello.rb(main):001:0> #!/usr/bin/env ruby
hello.rb(main):002:0*
hello.rb(main):003:0* class Hello
hello.rb(main):004:1> def initialize( hello )
hello.rb(main):005:2> @hello = hello
hello.rb(main):006:2> end
hello.rb(main):007:1> def hello
hello.rb(main):008:2> @hello
hello.rb(main):009:2> end
hello.rb(main):010:1> end
=> nil
hello.rb(main):011:0>
hello.rb(main):012:0* salute = Hello.new( "Hello, Mac!" )
=> #
hello.rb(main):013:0> puts salute.hello
Hello, Mac!
=> nil
2. rails consoleを使ってみよう
rails console
> Hotel.all
> Hotel.first
> Hotel.last
> Prefecture.first
new, save, createなどのコマンドを試そう。