Skip to content

Instantly share code, notes, and snippets.

View constructor-takes-partialy-initialized-object-good.rb
class Garden
def initialize(gardener)
@gardener = gardener
end
end
class Gardener
def initialize(workday, boots)
@workday = workday
@boots = boots
View constructor-takes-partialy-initialized-object-bad.rb
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 Jun 29, 2016
“new” Keyword in the Constructor or at Field Declaration
View new_in_constructor-good.rb
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 Jun 29, 2016
“new” Keyword in the Constructor or at Field Declaration
View new_in_constructor-bad.rb
class House
attr_reader :bedroom
def initialize
@bedroom = Bedroom.new
end
def enough_space?(people_count)
bedroom.beds_count >= people_count
end
View submission.rb
class Submission
MINIMAL_AGE = 18
attr_accessor :age
def can_attend?
age > MINIMAL_AGE
end
end
View react-native-styles.js
'use strict';
import React from 'react-native';
let {
StyleSheet,
} = React;
let colors = {
blue: '#1EC1F7',
View react-native-Connection.js
'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 });
}
View react-native-SubmissionsActionCreator.js
import ActionTypes from '../constants/ActionTypes';
import Connection from '../lib/Connection';
const _requestSubmissionsList = (submissionType) => {
return {
type: ActionTypes.REQUEST_SUBMISSIONS_LIST,
submission_type: submissionType
};
}
View react-native-ActionTypes.js
export default {
REQUEST_SUBMISSIONS_LIST: 'REQUEST_SUBMISSIONS_LIST',
RECEIVE_SUBMISSIONS_LIST: 'RECEIVE_SUBMISSIONS_LIST',
};
View react-native-SubmissionsReducer.js
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;