- Структура каталогов Ruby проекта
- Подключение файлов с помощью require
- Модули в Ruby
- Методы класса и модуля (статические методы)
- Блоки в Ruby
- Создание объектов
- Метод-конструктор
- Определение поведения (методов) и состояния (переменных экземпляра) объекта
- Доступ к переменным экземпляра за пределами области видимости объекта
- Объектная модель Ruby
- Контекст выполнения программы
- Ключевое слово
self
- Этапы проектирования класса
This file contains hidden or 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
var = %w[Ruby Java Scala Go JavaScript Elixir] | |
on = var.inject(Hash.new){ |result, language| result[language] = language.length; result } | |
p on | |
# Пояснения | |
# Итак, метод #inject позволяет проводить итерацию и одновременно "накапливать" результат в переменной | |
# Начальное значение этой накапливающей переменной мы задаём в аргументе метода #inject | |
# В нашем случае это Hash.new | |
# Далее начинается итерация 1 |
This file contains hidden or 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
# Your init script | |
# | |
# Atom will evaluate this file each time a new window is opened. It is run | |
# after packages are loaded/activated and after the previous editor state | |
# has been restored. | |
# | |
# An example hack to log to the console when each text editor is saved. | |
# | |
# atom.workspace.observeTextEditors (editor) -> | |
# editor.onDidSave -> |
This file contains hidden or 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
Links: | |
1. http://www.ikea.com/ru/ru/catalog/products/00142740/ | |
2. http://www.ikea.com/ru/ru/catalog/products/10234777/ | |
3. http://www.ikea.com/ru/ru/catalog/products/10251856/ | |
4. http://www.ikea.com/ru/ru/catalog/products/30146280/ | |
5. http://www.ikea.com/ru/ru/catalog/products/10234782/ | |
Item numbers: |
This file contains hidden or 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 reverse(string) | |
# gets (input from STDIN) isn't necessary cause you get string argument in this method | |
# input = gets.strip | |
# You should split your string by empty string to get an array of it's chars | |
string_array = string.split('') | |
# Class name should be started from a capital letter | |
new_word = Array.new |
This file contains hidden or 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 Ship | |
attr_accessor :name | |
def construct name = 'Andromeda' | |
@name = name | |
end | |
end |
This file contains hidden or 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_support/all' | |
module Gears | |
class Base | |
private_class_method :new | |
def initialize *methods | |
attrs = methods.extract_options! | |
self.class_eval{ attr_accessor *attrs.keys } |