0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

番外編 1. Rubyチュートリアル

Last updated at Posted at 2019-12-21

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などのコマンドを試そう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?