ASCII ruler generation
Not going to beat the dynamic languages today, but anyway...
Haskell, 341
import Data.List
main=interact$unlines.m.map read.words
m[l,r]|r>l=ᴛ.("┌│││└":).(++["┬ ─","┐│││┘"]).ʀ.t.ʀ.t.takeWhile((>4).length).ᴛ$[c"┬",c"│ ",[l,l+10..r]>>=h.show,c" ",c"─"]|True=["NaR"]
h s=p s$length s;p s@('-':_)l=r(6-l)ꜱ++s++r 4ꜱ;p s l=r 5ꜱ++s++r(5-l)ꜱ
ᴛ=transpose;ʀ=reverse;r=replicate;c=cycle
ꜱ=' ';t l@(c:o)|c!!2==ꜱ=t o|True=l
I took the liberty of exchanging the actual ASCII characters with better-looking unicode box drawing chars.
$ echo "-50 30" | runhaskell def0.hs
┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│-50 -40 -30 -20 -10 0 10 20 30 │
│ │
└─────────────────────────────────────────────────────────────────────────────────────┘
Python - 227 232
Supports entire specification
edit: improved generator expression.
Supporting right aligned negative numbers adds a surprising amount of code.
b,p,d,w,='|+- '
g=input
s=''.join(('%'+d[:i>0]+'10s')%i+['',9*w][i==0] for i in range(g(),g()+1,10)).strip()+w
m,n=s[0]==d and s.find(w)-1,len(s)
t=p+n*d+p
print['\n'.join([t,b+(w*m+'| '*n)[:n]+b,b+s+b,b+n*w+b,t]),'NaR'][n<9]
Sample outputs:
-30 30
+-----------------------------------------------------------------+
| | | | | | | | | | | | | | |
|-30 -20 -10 0 10 20 30 |
| |
+-----------------------------------------------------------------+
-30 -30
NaR
100 150
+------------------------------------------------------+
|| | | | | | | | | | | |
|100 110 120 130 140 150 |
| |
+------------------------------------------------------+
-1000 -950
+--------------------------------------------------------+
| | | | | | | | | | | | |
|-1000 -990 -980 -970 -960 -950 |
| |
+--------------------------------------------------------+
Python 2.7, 342 266 260 chars
a,b,c,d,m='+|- \n'
def f(y):x=map(str,(range(0,y+1,10)if y>0 else range(y,1,10)));h,g=len(x[-1])+1,len(x)-1;u=a+(c*10)*g+c*h+a;return'NaR'if y==0 else u+m+b+(b+d*4)*2*g+b+d*(h-1)+b+m+b+''.join(i.ljust(10)for i in x[:-1])+x[-1].ljust(h)+b+m+b+(d*10)*g+d*h+b+m+u
returns a tuple of each line string, which you can then print or save to a file (I prefer the latter for lengths longer than 70 becuase the console will jsut make it look messed up with wrapping)
Assumes y
to be a string (raw_input() n python, or sys.argv[1] if you wish to invoke via cmd) an integer (eg with input() in 2.x or int(input()) in 3.x)
I made this a function to be more flexible
edit: reduced to 266 characters. no longer returns a tuple, but a string instead. Now takes an integer instead of a string as the argument
edit2: reduced to 260 chars, single line function
note: does handle negative numbers, but doesn't right justify (I don't really htink the justification is too important anyways