ruby rails_route_recognizer.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby rails_route_recognizer.rb相关的知识,希望对你有一定的参考价值。

  class RouteRecognizer
    attr_reader :paths
    
    # To use this inside your app, call:
    # `RouteRecognizer.new.initial_path_segments`
    # This returns an array, e.g.: ['assets','blog','team','faq','users']

    INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}

    def initialize
      routes = Rails.application.routes.routes
      @paths = routes.collect {|r| r.path.spec.to_s }
    end

    def initial_path_segments
      @initial_path_segments ||= begin
        paths.collect {|path| match_initial_path_segment(path)}.compact.uniq
      end
    end

    def match_initial_path_segment(path)
      if match = INITIAL_SEGMENT_REGEX.match(path)
        match[1]
      end
    end
  end

以上是关于ruby rails_route_recognizer.rb的主要内容,如果未能解决你的问题,请参考以下文章

Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速

如何学习ruby?Ruby学习技巧分享

ruby Ruby脚本,看看是否用openssl编译了ruby

什么是ruby?

ruby和ruby ee

ruby入门知识:了解ruby历史及特性