/
fyi
executable file
·46 lines (44 loc) · 1.22 KB
/
fyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env fancy
# -*- fancy -*-
try {
if: (ARGV[1]) then: {
ident = ARGV rest join: " "
documentation = nil
match ident {
case /##/ ->
parts = ident split: "##"
obj = parts[0] eval
if: (parts[1]) then: |method_name| {
method = obj method: method_name
documentation = method documentation
}
case /#/ ->
parts = ident split: "#"
obj = parts[0] eval
if: (parts[1]) then: |method_name| {
method = nil
try {
method = obj instance_method: method_name
} catch NoMethodError {
# handle singleton methods if ARGV[1] is a singleton
method = obj method: method_name
}
documentation = method documentation
}
case _ ->
obj = ident eval
documentation = obj documentation
}
"Documentation for: '#{ident}':" println
documentation println
} else: {
["Prints the documentation string for a given object or one if its methods",
"Usage:",
"fyi [ObjectIdentifier]",
"fyi [ObjectIdentifier]#[MethodName]",
"",
"Example: fyi Array#each:"] println
}
} catch Exception => e {
"ERROR: #{e message}" println
}