-
Notifications
You must be signed in to change notification settings - Fork 1
Home
These courses contain two kinds of activity: on-line and off-line. On-line is our lessons. Off-line is your home tasks. The second part is optional, but I believe every home task is a key for consolidation the acquired knowledge into practice.
- Create a branch from last
masternamed _usernamehometaskN, where username is contributor's GitHub account name, N is a number of the related lesson (the same lettering is used for further agreements). - Write a simple, easy reading code with respect to most popular ruby style guide.
- Every task should be placed in a single file like lessonN/username_hometask.rb.
- Your work should contains samples which show how the script works.
rspec-expectationsis a preffered way to manage it. - Do your work due to a home task requirements.
- Push it to the remote server and create Pull Request on it.
- When you are ready to ask about a review - assign PR to me. It doesn't necessary mean the task is completed, you may need to clarify some things without a request for the final approval.
- You can receive some comments from me on the PR. Please, take a look at them. If the PR is assigned to you - the ball is in your court. So, apply suggestions, push latest changes and return PR to me (assign to me).
- When you feel your work is done, please squash your commits into one with a simple description "Add hometaskN from username" and force-push your branch before asking final review.
- If all conditions above are satisfied (name policy is respected, code is clear, commits are squashed and I am the last assignee of your PR), I will merge your task to the repo. Congrats, you can be proud of yourself!
- Describe
Fooclass which provide instance method#my_instance. The method should return either:evenif the receiver is an even instance of theFooclass or :odd otherwise. - Create one specific
Fooinstance which should return:uniqas a result of#my_instancemethod.
- Describe
Mmodule contains two methods. - When the module is included into a class:
- first method should become an instance method of the class, second one - a singleton method
- output in console result of action above: a list of added instance methods (should be one) and a list of added singleton methods (should be one too).
- Create class
Fooand includeMinto it.
HINT: you can use submodules in the M module.
- Develop you own enumerator method
:my_eachwhich would duplicate a logic of the system :each method. This method cannot use any other enumerator method inside, but can manage cycles, for example. - Place this method into
MyEachmodule and include it forArrayandHashobjects.
- Developer
LazyHashclass which should be pretty much the same as regularHashclass, but has specific purpose to work with procs. So, it should:
- manage only symbol keys;
- have a method accessor for each value in the hash by key (see OpenStruct concept as example which interface do we need);
- if the accessor points to proc value it should execute it and return result;
- each such execution should re-associate the value given by result of the proc execution;
- deal with
#method_missingto create these dynamic accessors. Do not use#define_methodor#define_singleton_methodfor such purpouse: it's a tack for next lesson.
- Add
#lazy?instance method forLazyHashwhich should provide information is related value a proc object or another kind of object.
NOTE: this task has no reference to similary named lazy pattern
Do the same what is described in task #4 with single difference: use #define_method or/and #define_singleton_method instead of #method_missing.
Write mini-DSL which would provide an interface to manage Person objects.
A syntax of an object description should be like:
class UserFactory
person :nonkor do
name 'Alex Mikitenko'
sex :male
age 31
end
person :zarina do
name 'Zarina Mikitenko'
sex :female
age 22
file 'zarina_mikitenko.yml'
end
endPerson objects could have only attributes: name, sex, age and file. Every attribute should be allowed to be overridden. An access to them should look like:
puts Person.nonkor.inspect # => #<Person:0x007ff51a033948>
puts Person.nonkor.name # => 'Alex Mikitenko'
puts Person.zarina.sex # => :female
puts Person.zarina.age # => 22
puts Person.zarina.file # => 'zarina_mikitenko.yml'Just after creation, an object should be serialized in a corresponding json file (see file attribute). If file attribute is not specified, symbol which is used for defining object should be used instead. In our case we would have files: nonkor.yml and zarina_mikitenko.yml.
Every attribute should be allowed to be overridden. Person object should also provide method #load! to deserialize object (restore all attributes from a corresponding json file) and #save! to serialize it (update attributes in a corresponding json file).
Example:
Person.zarina.load
Person.zarina.age = 10
Person.zarina.save! # => update zarina_mikitenko.yml, her age should be stored as `10` in a result.