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
[ | |
{ | |
"id": "A1", | |
"title": "The Lean Startup", | |
"complete": false, | |
"progress": 45, | |
"finishedOn": "", | |
"author": "Eric Ries", | |
"rating": 0, | |
"tags": ["business", "tech"], |
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 reverse_alternate(string) | |
words = string.split(' ') | |
words.each_with_index { |word, i| word.reverse! if i.odd? } | |
return words.join(' ') | |
end | |
reverse_alternate('one two three four') #=> 'one owt three ruof' |
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 reverse_alternate(string) | |
# 1. Break the string down into an array of words. | |
words = string.split(' ') | |
# 2. Loop over each word in the array. | |
words.each_with_index do |word, index| | |
# - if the index is odd, change the word so it is reversed. | |
# - if the index is even, leave it as it is. | |
word.reverse! if index.odd? |
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 reverse_alternate(string) | |
# 1. Break the string down into an array of words. | |
words = string.split(' ') | |
# 2. Loop over each word in the array. | |
# - if the index is odd, change the word so it is reversed. | |
# - if the index is even, leave it as it is. | |
# 3. Join all the words in the array together so they are a string again, with spaces between them. | |
# 4. Return the new string we made. | |
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
def reverse_alternate(string) | |
# 1. Break the string down into an array of words. | |
# 2. Loop over each word in the array. | |
# - if the index is odd, change the word so it is reversed. | |
# - if the index is even, leave it as it is. | |
# 3. Join all the words in the array together so they are a string again, with spaces between them. | |
# 4. Return the new string we made. | |
end | |
reverse_alternate('one two three four') #=> 'one owt three ruof' |
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 reverse_alternate(string) | |
# 1. Break the string down into an array of words. | |
# 2. Loop over each word in the array. | |
# - if the index is odd, change the word so it is reversed. | |
# - if the index is even, leave it as it is. | |
# 3. | |
end | |
reverse_alternate('one two three four') #=> 'one owt three ruof' |
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 reverse_alternate(string) | |
# 1. Break the string down into an array of words. | |
# 2. | |
end | |
reverse_alternate('one two three four') #=> 'one owt three ruof' |
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 reverse_alternate(string) | |
#your code here | |
end | |
reverse_alternate('one two three four') #=> 'one owt three ruof' |
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 ValueObject | |
NotImplementedInSubclassError = Class.new(StandardError) | |
def initialize | |
raise NotImplementedInSubclassError, 'Value Objects must implement a constructor' | |
end | |
# This is not ideal, since it will fail if the object contains any instance variables that are not exposed via getter methods. | |
def ==(other) | |
return false unless self.class == other.class |
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 'awesome_print' | |
class ExpectationTarget | |
def initialize(obj) | |
@object = obj | |
end | |
def to(matcher) | |
raise ArgumentError, 'Not a matcher' unless matcher.respond_to?(:matches?) | |
test_match(matcher.matches?(@object)) |