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
# Ruby 3.1+ | |
users = [ | |
{ name: "Yukihiro Matsumoto", age: 57 }, | |
{ name: "Kabosu the Shiba Inu", age: 16 }, | |
{ name: "Thiago Massa", age: 33 } | |
] | |
def fetch_age_from_person(person, hash) | |
hash => [*, {name: ^person, age: age}, *] |
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
k = [1] | |
h = {} | |
h[k] = 1 | |
k << 2 | |
h[k] = 2 | |
p h # {[1, 2]=>1, [1, 2]=>2} | |
k = [1] | |
h = {k => 1, (k << 2) => 2} |
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
# *************************************** | |
# Oauth - Access Token, Secret 取得処理 | |
# *************************************** | |
require 'oauth' | |
class TwitterAccessToken | |
SITE_URL = "https://twitter.com" | |
def get_token | |
# Consumer 情報入力 |
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
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
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
# RSpec matcher for alias_method. | |
# https://gist.github.com/1950961 | |
# Usage: | |
# | |
# describe User do | |
# it { should alias_from(:username).to(:email) } | |
# end | |
RSpec::Matchers.define :alias_from do |alias_method| |
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
namespace :spree do | |
desc "Export Products to CSV File" | |
task :export_products => :environment do | |
require 'fastercsv' | |
products = Product.find(:all) | |
puts "Exporting to #{RAILS_ROOT}/products.csv" | |
FasterCSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv| | |
csv << ["id", "name", "description","sku", "master_price" ] |