2009-10-28 10 views
15

क्या कोई गेटो स्टेटमेंट की तरह निर्दिष्ट लाइन पर शुरू करने का कोई तरीका है?क्या रूबी में कोई बयान है?

+8

अनिवार्य xkcd हास्य: http://xkcd.com/292/ – LiraNuna

+1

कोई विशेष कारण आप जानना चाहता हूँ? –

+0

मुझे पता है कि आप rspec में कर सकते हैं। स्रोत को देख सकते हैं। –

उत्तर

25

सबसे पहले, यह कथन होगा, कमांड नहीं। दूसरा, ruby-goto देखें। तीसरा, ध्यान दें

श्रेणी: लाइब्रेरी/ईविल

+11

वाह, "श्रेणी: पुस्तकालय/बुराई"। – LiraNuna

+3

पहले मैंने सोचा कि यह एक मजाक था, लेकिन वास्तव में एक श्रेणी है: पुस्तकालय/बुराई। वर्तमान में इसमें रूबी-गोटो शामिल है, साथ ही * segfault4r *: "यह एक मॉड्यूल है जो एक सेगफॉल्ट को मजबूर करता है। – Colin

+0

रूबी गोटो लिंक मर चुका है। –

2

मैं इतना विश्वास नहीं है (और, द्वारा वह सब पवित्र है, यह नहीं करना चाहिए)।

लेकिन यदि आप वास्तव में मासोचिस्टिक महसूस कर रहे हैं तो इसके लिए goto मॉड्यूल है।

4

रूबी कमांड लाइन स्विच -x है।

 
-x[directory] Tells Ruby that the script is embedded in a message. 
       Leading garbage will be discarded until the first that 
       starts with “#!” and contains the string, “ruby”. Any 
       meaningful switches on that line will applied. The end of 
       script must be specified with either EOF, ^D (control-D), 
       ^Z (control-Z), or reserved word __END__. If the direc‐ 
       tory name is specified, Ruby will switch to that directory 
       before executing script. 

बीटीडब्ल्यू, मुझे पूरा यकीन है कि रूबी-गोटो, उम, एक मजाक था। मुझे विश्वास नहीं है कि डाउनलोड लिंक ने कभी काम किया है। या क्या मुझे बस लोगों को यह इंगित करना चाहिए और चुप रहना चाहिए? मैं जानता हूँ कि कभी नहीं ...

मैं माणिक गोटो की घोषणा के बाद रयान की अगली पंक्ति इसे पसंद किया:

अगले बुराई मॉड्यूल के लिए तैयार रहें ... माणिक malloc! आपका दिन शुभ हो।

रयान स्पष्ट रूप से एक प्रतिभा है।

1

गोटो lib हमारे साथ अब भी है: डी https://rubygems.org/gems/goto/versions/0

भावी पीढ़ी के लिए पूरे मणि का संरक्षण:

STACK = [] 

class Label 
    attr_accessor :name; 
    attr_accessor :block; 

    def initialize(name, block); 
    @name = name 
    @block = block 
    end 

    def ==(sym) 
    @name == sym 
    end 
end 

class Goto < Exception; 
    attr_accessor :label 
    def initialize(label); @label = label; end 
end 

def label(sym, &block) 
    STACK.last << Label.new(sym, block) 
end 

def frame_start 
    STACK << [] 
end 

def frame_end 
    frame = STACK.pop 
    idx = 0 

    begin 
    for i in (idx...frame.size) 
     frame[i].block.call if frame[i].block 
    end 
    rescue Goto => g 
    idx = frame.index(g.label) 
    retry 
    end 
end 

def goto(label) 
    raise Goto.new(label) 
end 
संबंधित मुद्दे