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 spec_helper | |
--color | |
--format documentation |
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 scrub_uri | |
uri.strip! | |
unless uri.slice(0,4) == "http" do | |
uri = uri.prepend "http://" | |
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
<%= debug(params) if Rails.env.development? %> | |
<%= debug(session) if Rails.env.development? %> |
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
<%= simple_form_for [topic, post] do |f| %> | |
<%= f.input :title %> | |
<%= f.input :body, rows: 8 %> | |
<% if post.image? %> | |
<div class="form-group"> | |
<p>Current image</p> | |
<%= image_tag( current_user.image.thumb.url ) %> | |
</div> | |
<% end %> | |
<%= f.input :image, as: :file %> |
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 Array | |
def new_any?(&block) | |
if block_given? | |
selected = self.select(&block) | |
else | |
selected = self | |
end | |
if selected.length == 0 | |
false |
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 Array | |
def new_map | |
new_array = [] | |
each do |item| | |
new_array << yield(item) | |
end | |
new_array | |
end | |
def new_select!(&block) |
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 new_map(array) | |
new_array = [] | |
array.each do |item| | |
new_array << yield(item) | |
end | |
new_array | |
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
def add_two(array) | |
array.map { |item| "#{item} + 2 = #{ item+2 }" } | |
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
def merge_us(hash1, hash2) | |
hash1.merge(hash2) | |
end | |
def my_keys(hash) | |
hash.keys | |
end | |
def do_i_have?(h ={},keys) | |
h.keys.sort == keys.sort |
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 Title | |
attr_reader :string | |
def initialize(string) | |
@string = string | |
end | |
def fix | |
# A neat Ruby trick for making an array of strings | |
# Equivalent to: ['a', 'and', 'the', 'of'] |