Skip to content

Instantly share code, notes, and snippets.

View zgfif's full-sized avatar
🙃

Pasha Bratanov zgfif

🙃
  • Odesa, Ukraine
View GitHub Profile
@zgfif
zgfif / program1.rb
Created December 15, 2018 20:24
Реалізувати програму, яка буде приймати аргументом рядок (String) і рахувати скільки разів зустрічається кожна літера в цьому рядку.
def count_letters(text)
array = []
text = text.downcase
text.each_char do |char|
if char =~ /[A-Za-z]+/
count = text.count(char)
array << [char, count]
end
end
array = array.uniq
@zgfif
zgfif / program2_animal.rb
Last active December 24, 2018 11:03
Animal
class Animal
attr_reader :distance
def initialize
@distance = 0
end
def step!
@distance += 1
end
require 'active_model'
class Person
include ActiveModel::Validations
attr_accessor :name, :age
def initialize(name: nil, age: nil)
@name = name
@age = age
class Calculator
def initialize(var_x, var_y)
@var_x = var_x
@var_y = var_y
end
def divide
@var_x / @var_y
end
end
require 'rspec'
require 'rspec/its'
require_relative 'task_seven'
RSpec.describe TaskSeven do
let(:array) { [5, -3, 3, -5, 6, 6, 6, -1, 0, 2] }
subject { described_class.new array }
its(:number_elements_after_max) { should eq 3 }
require 'active_model'
class Person
include ActiveModel::Validations
attr_accessor :name, :age, :size
def initialize name: nil, age: nil, size: nil
@name = name
@age = age
def hello_message options = {}
first_name = options.fetch :first_name
last_name = options.fetch :last_name
"Hello, #{first_name} #{last_name}"
end
data = {first_name: 'Lero4ka', last_name: 'Melnik' }
# p hello_message data
def summarize *args
"#{args[0]} #{args[1]} #{args[2]}"
end
p summarize 1,2,3,4,5
ar = [1, 2, 4]
def square_values array
array.map! {|e| e * e }
end
p square_values ar
@zgfif
zgfif / act_as.rb
Last active December 28, 2018 21:14
module ActsAsWalker
attr_reader :distance
def walk!
@distance += 1
end
end
module ActsAsSpeaker
attr_reader :speak, :gills