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 :: get specific key value from array of hashes in ruby 
Ruby :: ruby substring 
Ruby :: write heroku logs 
Ruby :: ruby-on-rails 
R :: export csv in r 
R :: R, how to count missing values in a column 
R :: automatically wrap r text label ggplot 
R :: r convert string to list of characters 
R :: r loops 
R :: r dataframe filter endswith 
R :: r column to rownames 
R :: create file in r 
R :: remove all empty strings from R 
R :: grid.arrange 
R :: principal component analysis in r 
R :: ggplot2 black and white theme 
R :: turn row names into column in r 
R :: filter only NA column in R 
R :: r sapply syntax 
R :: geom_point transparency 
R :: if condition is met skip to next iteration in a for loop in r 
R :: how to load html file to r studio 
R :: rename variable in r dplyr 
R :: not equals r 
R :: change to posixct in r 
R :: generate random values binomial law in r 
R :: R caTools library with Mandelbrot set 
Rust :: how to clear the console rust 
Rust :: rust .0 
Rust :: rust copy to clipboard 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =