Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

class Garden
def initialize(gardener)
@gardener = gardener
end
end
class Gardener
def initialize(workday, boots)
@workday = workday
@boots = boots
class Garden
def initialize(gardener)
gardener.set_workday(Workday.new)
gardener.set_boots(BootsWithMassiveStaticInitBlock.new)
@gardener = gardener
end
end
class Gardener
def set_workday(workday)
@lesniakania
lesniakania / new_in_constructor-good.rb
Last active June 29, 2016 13:53
“new” Keyword in the Constructor or at Field Declaration
class House
attr_reader :bedroom
def initialize(bedroom)
@bedroom = bedroom
end
def enough_space?(people_count)
bedroom.beds_count >= people_count
end
@lesniakania
lesniakania / new_in_constructor-bad.rb
Last active June 29, 2016 13:51
“new” Keyword in the Constructor or at Field Declaration
class House
attr_reader :bedroom
def initialize
@bedroom = Bedroom.new
end
def enough_space?(people_count)
bedroom.beds_count >= people_count
end
class Submission
MINIMAL_AGE = 18
attr_accessor :age
def can_attend?
age > MINIMAL_AGE
end
end
'use strict';
import React from 'react-native';
let {
StyleSheet,
} = React;
let colors = {
blue: '#1EC1F7',
'use strict'
import Axios from 'axios';
const BASE_URL = 'http://localhost:3000/api';
class ApiConnector {
get(path, data = {}) {
return Axios.get(`${BASE_URL}${path}`, { params: data });
}
import ActionTypes from '../constants/ActionTypes';
import Connection from '../lib/Connection';
const _requestSubmissionsList = (submissionType) => {
return {
type: ActionTypes.REQUEST_SUBMISSIONS_LIST,
submission_type: submissionType
};
}
export default {
REQUEST_SUBMISSIONS_LIST: 'REQUEST_SUBMISSIONS_LIST',
RECEIVE_SUBMISSIONS_LIST: 'RECEIVE_SUBMISSIONS_LIST',
};
import ActionTypes from '../constants/ActionTypes';
let SubmissionsReducer = (state = {}, action) => {
let newState;
switch (action.type) {
case ActionTypes.RECEIVE_SUBMISSIONS_LIST:
newState = {};
action.submissions.forEach((s) => {
newState[s.id] = s;