Notice
Recent Posts
Recent Comments
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

INSPECT

[Ruby] 1 본문

Ruby on Rails - 멋쟁이 사자처럼

[Ruby] 1

INSPECT 2017. 1. 26. 12:59
variable_name = gets.chomp

gets is the Ruby method that gets input from the user. When getting input, Ruby automatically adds a blank line (or newline) after each bit of input; chomp removes that extra line. (Your program will work fine without chomp, but you'll get extra blank lines everywhere.)


As you might have noticed, Ruby's not really returning any feedback to us. We want to be able to see our string formatting in action! For this, we'll need one more new piece of syntax.

If you define a variable monkeythat's equal to the string "Curious George", and then you have a string that says "I took #{monkey} to the zoo", Ruby will do something called string interpolation and replace the #{monkey} bit with the value of monkey—that is, it will print "I took Curious George to the zoo". We can do the same thing here! For example:

first_name = "Kevin"
puts "Your name is #{first_name}!"

will print "Your name is Kevin!"


ex)


참고 : codecademy.com

'Ruby on Rails - 멋쟁이 사자처럼' 카테고리의 다른 글

[Ruby]3. Hash  (0) 2017.01.26
[Ruby]2  (0) 2017.01.26
[CSS] 웹 폰트 사용하기  (0) 2017.01.20
[C9] css: command not found 오류  (0) 2017.01.20
C9에서 Git에 commit 하기  (0) 2017.01.20
Comments