Let's look at an innocuous piece of ruby. Consider some view code showing a user's name and phone number:
"#{first_name} #{last_name} #{phone}"
Great - this is very succinct, readable, and can easily be extracted to a method in a
$(function () { | |
//Config datepiker matrializecss () language | |
$('.datepicker').pickadate({ | |
selectMonths: true,//Creates a dropdown to control month | |
selectYears: 15,//Creates a dropdown of 15 years to control year | |
//The title label to use for the month nav buttons | |
labelMonthNext: 'Proximo Mês', | |
labelMonthPrev: 'Mês Anterior', | |
//The title label to use for the dropdown selectors | |
labelMonthSelect: 'Selecionar Mês', |
<%# Put this code snippet between the <head></head>-tags in your application layout and %> | |
<%# replace 'UA-XXXXXXXX-X' with your own unique Google Analytics Tracking ID %> | |
<%# ... %> | |
<head> | |
<%# ... %> | |
<% if Rails.env.production? %> | |
<script type="text/javascript"> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
#!/usr/bin/env ruby | |
require "openssl" | |
require "time" | |
begin | |
require "origami" | |
rescue LoadError | |
abort "origami not installed: gem install origami" | |
end |
describe 'Expectation Matchers' do | |
describe 'equivalence matchers' do | |
it 'will match loose equality with #eq' do | |
a = "2 cats" | |
b = "2 cats" | |
expect(a).to eq(b) | |
expect(a).to be == b # synonym for #eq |
class DummyController < ApplicationController | |
def do | |
render json: { balance: 50 } | |
end | |
end |
HTTP status code symbols for Rails | |
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
Status Code Symbol | |
1xx Informational | |
100 :continue | |
101 :switching_protocols | |
102 :processing |
<!doctype html> | |
<html> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
var spData = null; | |
function doData(json) { | |
spData = json.feed.entry; | |
} | |
'.source.ruby': | |
'describe (String)': | |
'prefix': 'des' | |
'body': 'describe "${1:subject}" do\n $0\nend' | |
'describe (type)': | |
'prefix': 'dest' | |
'body': 'describe ${1:Type} do\n $0\nend' | |
'describe (type, string)': | |
'prefix': 'dests' | |
'body': 'describe ${1:Type}, "${2:description}" do\n $0\nend' |