2013-06-24 16 views
7

Ho guardato attraverso lo documentation of the URI class in ruby ​​ma non sono riuscito a trovare un modo per estrarre l'ancora (HTML) dall'istanza. Per esempio, inEstrazione dell'ancora da un URL in ruby ​​

http://example.com/index.php?q=something#anchor 

Vorrei ottenere il testo anchor. La soluzione banale è manipolare il testo con espressioni regolari, ma se c'è un metodo per farlo, allora è molto meglio.

risposta

9

Il modulo URI fornisce un attributo fragment. ad esempio:

>> uri = URI("http://example.com/index.php?q=something#anchor") 
>> uri.fragment 
=> "anchor"