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 **

# アスタリスク2つつけるとハッシュになる
def huga(**a) # def huga(a = {})と同意
  p a
end

huga(b:1,c:2)
#=> {:b=>1, :c=>2}

def huga_2(a)
  p a 
end
huga_2({a:1,b:2})
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 :: diff between .. and ... in ruby 
Ruby :: rails admin overwrite view 
Ruby :: how to open ruby console 
Ruby :: csv parse ruby 
Ruby :: pick element from space separated list that is part of params hash 
Ruby :: rails db:drop not working 
Ruby :: rails class reminders belongs_to creator 
Ruby :: rails update column without callbacks 
Ruby :: devise remove * sign up form 
Ruby :: devise manually sign out user 
Ruby :: rspec change matcher 
Ruby :: replace strring by another string ruby 
R :: add a vertical line in ggplot 
R :: Drop rows with missing values in R 
R :: how to set the first column as row names in r 
R :: how to match two time series in r 
R :: negative binomial distribution rstudio 
R :: list to dataframe in r 
R :: r concatenate data frame 
R :: correlation matrix in r 
R :: reorder levels of a factor in r 
R :: r find nas in dataframe 
R :: how to create for loop through columns and count non na cells by group in r 
R :: order barplot ggplot2 by value 
R :: read xlsx in r 
R :: Hello Shiny Server Logic 
R :: generate pair in r 
R :: r select columns by name 
R :: r select column names starting with 
R :: r runif 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =