This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = ['ant','bbe','cat','dog','elk'] | |
a = %w{ ant bee cat dog elk} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nst_section = { | |
:cello => '絃楽器', | |
:clarinet => '木管楽器' | |
} | |
#キーがシンボルでない場合、rubyが1.9でない場合はこちらは使用できない | |
inst_section = { | |
cello: '絃楽器' | |
clarinet: '木管楽器’ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if | |
if count > 10 | |
puts "もう一度挑戦してください。" | |
elsif tries == 3 | |
puts "あなたの負けです。" | |
else | |
puts "数字を入力してください。" | |
end | |
#while |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
animals = %w( ant bee cat dog elk ) #配列を作成 | |
animals.each{|animal| puts animal } | |
#3回繰り返す。 | |
3.times { print "ホー!" } #~> ホー!ホー!ホー! | |
#&接頭演算子 | |
def wrap &b | |
print "さんたのことば:" | |
3.times(&b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
content = load_blog_data(file_name) | |
rescue BlogDataNotFound | |
STDERR.puts "ファイル#(file_name}がみつかりません" | |
rescue BlogDataFormatError | |
STDERR.puts "#{file_name}内のブログデータが壊れています" | |
rescue Exception => exc | |
STDERR.puts "#{file_name} ロード時の一般エラー:#{exc.message}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Greeter | |
attr_accessor :name #getter/setter | |
attr_reader :greeting #getter | |
attr_writer :age #setter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#破壊的メソッド | |
empty? | |
#デフォルト値などをかえしたい時に欲使う | |
a || b | |
#以下の2つは同じ意味 | |
count ||= 0 | |
count = count || 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= f.text_area :description, rows: 6 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# application.html.erb | |
<body class='<%= controller.controller_name %>'> | |
# Procucts.css.scss | |
.products { | |
table { | |
border-collapse: collapse; | |
} | |
table tr td { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#seeds.rb | |
Product.delete_all | |
Product.create(title: 'Programming Ruby 1.9', | |
description: | |
%{<p> | |
Ruby is the fastest growing and | |
</p> | |
}, | |
imge_url: 'ruby.jpg', |
OlderNewer