Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby *

# アスタリスク単体で、受け取った引数を無視できる
def hoge_3(bar, *)
  p "#{bar} world!!!"
end

hoge_3('Hello', 'hoge', 'fuga') 
#=> "Hello world!!!"

# 仮引数ではなく実引数にアスタリスクをつけると、配列を展開して渡される
def foo(bar, baz, qux)
  p bar << baz << qux
end

foo(*['Hello', 'World', '!!!']) # foo('Hello','World','!!!')と同意
#=> "HelloWorld!!!"
Comment

ruby *

# 引数にアスタリスク1つをつけると配列になる
def hoge_1(*a)
  p a
end

hoge_1(1)
#=> [1]
hoge_1(1,2)
#=> [1, 2]

#メソッドの仮引数の前に* を付けると、複数の引数をまとめて配列として受け取ることができます。
#ただしこの可変長引数は1メソッドにつき、1つだけしか指定できません。
def hoge_2(bar, *baz)
  p bar, baz
end
hoge_2(1,2,3)
#=> 1
#=> [2,3]
Comment

ruby

Ruby is python but with slightly different syntax
Comment

ruby

this is my application_controller.rb file

private

  def default_url_options
    { locale: I18n.locale }
  end


  def set_locale
    I18n.locale = extract_locale || I18n.default_locale
  end

  def extract_locale
    parsed_locale = params[:locale]
    I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale.to_sym : nil
  end```

This is my route.rb file

  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
    get 'careers' => 'pages#careers', :as => :careers
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: date class to unix timestamp ruby 
Ruby :: creating model in ruby on rails 
Ruby :: rails send email from console 
Ruby :: how add an index column in rails 
Ruby :: ruby hello 
Ruby :: ruby while loops 
Ruby :: ruby rails controller 
Ruby :: rails parse boolean 
Ruby :: Ruby instance variabnl get 
Ruby :: how to reset migrations rails 
Ruby :: font awesome icon rails submit button 
Ruby :: ruby find max value in array 
Ruby :: ruby get instance variables without accessor 
Ruby :: ffi gem error mac 
Ruby :: deep copy and shallow copy in ruby 
Ruby :: ruby array last 
Ruby :: rails destroy something from db 
Ruby :: rails many to many relationship same model 
Ruby :: rails rspec destroy data after each test 
Ruby :: rspec factory create_list with association 
Ruby :: rails render json only some attributes 
Ruby :: ruby URI.open with proxy 
Ruby :: ruby hash except nested 
Ruby :: ruby String split second parameter 
Ruby :: model with array rails 
R :: how to fill na values in r 
R :: reverse row order dataframe R 
R :: how to use recursion in r 
R :: turn matrix into dataframe r 
R :: ggplot2 font times new roman 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =