Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 61 lines (41 sloc) 1.517 kB
aad602f @lsegal Add support and readme files
authored
1 # Friend
2
3 Adds fine-grained visibility semantics to Ruby, allowing you to make methods
4 visible only to specific classes (and their subclasses).
5
6 ## Installing
7
8 $ [sudo] gem install friend
9
10 Or build it manually:
11
12 $ git clone git://github.com/lsegal/friend
13 $ cd friend
14 $ rake install
15
16 ## Using
17
18 To use the library, require it and call `friend` (aka. `export`) from
19 any module/class to export a method to a list of specific classes in the
20 form:
21
22 export :methodname, Class1, Class2, ...
7436607 @lsegal Explicitly explain that friend and export are one and the same
authored
23
24 **Note**: `export` is an alias of `friend`. They do the exact same thing, though
25 depending on your semantics one terminology might be more suited than the
26 other.
aad602f @lsegal Add support and readme files
authored
27
28 ## Example
29
30 require 'friend'
31
32 class A; def bar; D.new.foo end end
33 class B; def bar; D.new.foo end end
34 class C; def bar; D.new.foo end end
35
36 class D
37 def foo; "HELLO WORLD!" end
38
39 # Export to A and B, but not C
40 export :foo, A, B
41 end
42
43 puts A.new.bar
44 puts B.new.bar
45 puts C.new.bar
46
47 # Output:
48 #
49 # HELLO WORLD!
50 # HELLO WORLD!
51 # export_features.rb:5:in `bar': `foo' is not accessible to C:Class (NoMethodError)
52 # from export_features.rb.rb:16:in `<main>'
53
54 More examples can be found in the `example/` directory.
55
56 ## License & Author
57
58 Friend is written by Loren Segal &copy; 2010, licensed under the BSD license.
59 This software can be redistributed and modified so long as it maintains the
60 copyright notice and `LICENSE` file. See `LICENSE` for more information.
Something went wrong with that request. Please try again.