管理者
field | type | key | extra |
---|
class Book | |
attr_accessor :title | |
def initialize(title) | |
@title = title | |
end | |
def rename_title(title) | |
@title = title | |
end |
Q1-1 以下の問いに対して、Rubyクラスを具体例に出してメンターに説明せよ。 | |
オブジェクトとは | |
あるテーマを持ったデータと処理のまとまり。例えば、stringオブジェクトは文字列というデータと、to_iやlengthなどのメソッド(処理)のまとまり。 | |
クラスとは | |
オブジェクトの種類のこと。設計図のようなもので、オブジェクトの属性やふるまいを定義している。例えばstringクラスは、文字列を扱うクラスで、 | |
文字列を整数に変換するメソッドや長さを図るメソッドなどのふるまいを定義している。 |
array = [9,6,3,4,5,2,1,3,1,6] | |
def is_unique?(array) | |
num = 0 | |
results =[] | |
hash = {} | |
array.each_with_index do |value, i| | |
array.each_with_index do |num, i2| | |
if i == i2 | |
next |
array = [9,6,3,4,5,2,1,3,1,6] | |
def is_unique?(array) | |
num = 0 | |
results =[] | |
array.each_with_index do |value, i| | |
array.each_with_index do |num, i2| | |
if i == i2 | |
next | |
elsif num == value |
array = [9,6,3,4,5,2,1,3,1,6] | |
def is_unique?(array) | |
num = 0 | |
results =[] | |
array.each_with_index do |value, i| | |
array.each_with_index do |num, i2| | |
if i == i2 | |
next | |
elsif num == value |
array = [9,66,3] | |
def find_min(array) | |
array.sort! { |a, b| a<=>b } | |
p array | |
return array[0] | |
end | |
p find_min(array) |
array = [1,2,3] | |
num = gets.to_i | |
def has_num?(array, num) | |
hasNum = false | |
array.each do |n| | |
if n == num | |
hasNum = true | |
end | |
end | |
return hasNum |
a1 = [1,2,3] | |
a2 = a1.map { |n| n*2 } |
num = 0 | |
while num < 101 | |
if num % 15 == 0 | |
puts 'FizzBuzz' | |
elsif num % 3 == 0 | |
puts 'Fizz' | |
elsif num % 5 == 0 | |
puts 'Buzz' | |
else | |
puts num |