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
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 |
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 Animal | |
attr_reader :distance | |
def initialize | |
@distance = 0 | |
end | |
def step! | |
@distance += 1 | |
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
require 'active_model' | |
class Person | |
include ActiveModel::Validations | |
attr_accessor :name, :age | |
def initialize(name: nil, age: nil) | |
@name = name | |
@age = age |
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 Calculator | |
def initialize(var_x, var_y) | |
@var_x = var_x | |
@var_y = var_y | |
end | |
def divide | |
@var_x / @var_y | |
end | |
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
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 } |
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
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 |
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
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 |
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
def summarize *args | |
"#{args[0]} #{args[1]} #{args[2]}" | |
end | |
p summarize 1,2,3,4,5 |
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
ar = [1, 2, 4] | |
def square_values array | |
array.map! {|e| e * e } | |
end | |
p square_values ar |
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
module ActsAsWalker | |
attr_reader :distance | |
def walk! | |
@distance += 1 | |
end | |
end | |
module ActsAsSpeaker | |
attr_reader :speak, :gills |
OlderNewer