Skip to content

Commit 0e73b6f

Browse files
committed
Add samples
1 parent 387431a commit 0e73b6f

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ Ruby
250250
* Use `Set`, not `Array`, for arrays with unique elements. The lookup is faster.
251251
* Use single-quotes for strings unless interpolating.
252252

253+
[Sample](https://github.com/thoughtbot/style-guide/blob/master/ruby-sample.rb)
254+
253255
Rails
254256
-----
255257

@@ -370,6 +372,8 @@ Testing
370372
* Use one expectation per `it` block.
371373
* Use [stubs and spies](http://goo.gl/EciDJ) (not mocks) in isolated tests.
372374

375+
[Sample](https://github.com/thoughtbot/style-guide/blob/master/rspec-sample.rb)
376+
373377
Browsers
374378
--------
375379

rspec-sample.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe SomeClass do
2+
it "does something for #some_method" do
3+
end
4+
5+
context "#other_method" do
6+
it "does something in one case" do
7+
end
8+
9+
it "does something else in other cases" do
10+
end
11+
12+
# methods go here
13+
end
14+
end

ruby-sample.rb

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class SomeClass
2+
SOME_CONSTANT = 'upper case name'
3+
4+
def initialize(attributes)
5+
@some_attribute = attributes[:some_attribute]
6+
@another_attribute = attributes[:another_attribute]
7+
end
8+
9+
def method_with_arguments(argument_one, argument_two)
10+
this_is_a_really_line_that_should_be_broken_up_over_multiple_lines_and.
11+
every_line_but_the_first_is_indented
12+
end
13+
14+
def method_with_multiline_block
15+
items.each do |item|
16+
do_something_with_item
17+
end
18+
end
19+
20+
def method_with_single_line_block
21+
items.map { |item| item.some_attribute }
22+
end
23+
24+
def method_that_returns_an_array
25+
[item_one, item_two]
26+
end
27+
28+
def method_that_returns_a_hash
29+
{ :key => 'value' }
30+
end
31+
32+
def method_that_uses_infix_operators
33+
left + middle - right
34+
end
35+
36+
def method_without_arguments
37+
method_start
38+
39+
if complex_condition?
40+
positive_branch
41+
else
42+
negative_branch
43+
end
44+
45+
rest_of_body
46+
end
47+
48+
def self.class_method
49+
method_body
50+
end
51+
52+
private
53+
54+
def complex_condition?
55+
part_one? && part_two?
56+
end
57+
end

0 commit comments

Comments
 (0)