ruby 红宝石团队树屋
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 红宝石团队树屋相关的知识,希望对你有一定的参考价值。
for number in 1..30
puts number
end
------
for number in 1..30
if number == 5
puts "I like 5"
end
puts number
end
rubyonrails-basics.rb
Ruby Copy Raw
The "Hello world!" program is a simple program that displays some text on the screen.
ruby -v - what version is running
treehouse:~/workspace$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
treehouse:~/workspace$ irb
irb(main):001:0> puts "Hello world"
Hello world
=> nil
irb(main):002:0>
Exit irb:
irb(main):001:0> exit
Create a file called "hello.rb" and place the following in the file:
puts "Hello World!"
Run the program we just created by typing the following:
ruby hello.rb
Rules
irb(main):001:0> exit
Create a file called "hello.rb" and place the following in the file:
puts "Hello World!"
Run the program we just created by typing the following:
ruby hello.rb
------------
puts
put string on the screen
gets
get string input
-------------
Create a variable name = "priss"
file
name = "priss"
puts "hello"
puts name
console
treehouse:~/workspace$ ruby hello.rb
hello
Jason
-------------
Put name on 1 line
name = "Jason"
puts "hello #{name}!"
treehouse:~/workspace$ ruby hello.rb
hello Jason!
-------------
print "Please enter your name: "
name = gets
puts "hello #{name}!"
treehouse:~/workspace$ ruby hello.rb
Please enter your name: priss
hello priss
!
treehouse:~/workspace$
-------------
Print out your name:
name = "Jason"
puts "Hello #{name}"
Get input from the user:
name = gets
puts "Hello #{name}"
Run a Ruby program called "hello.rb":
ruby hello.rb
Prompt the user for their name:
print "Please enter your name: "
name = gets
puts "Hello #{name}"
#
以上是关于ruby 红宝石团队树屋的主要内容,如果未能解决你的问题,请参考以下文章