Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 46 lines (44 sloc) 1.254 kb
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
}
Something went wrong with that request. Please try again.