るりまサーチ

最速Rubyリファレンスマニュアル検索!
4件ヒット [1-4件を表示] (0.152秒)
トップページ > クエリ:r[x] > クエリ:body[x] > クエリ:param[x] > クラス:Data[x]

別のキーワード

  1. _builtin to_r
  2. open3 pipeline_r
  3. matrix elements_to_r
  4. fileutils rm_r
  5. fileutils cp_r

ライブラリ

検索結果

Data.define(*args) -> Class (131.0)

Data クラスに新しいサブクラスを作って、それを返します。

...
Data
クラスに新しいサブクラスを作って、それを返します。

サブクラスでは値オブジェクトのメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # =>...
...Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
fred.age = 6 # => NoMethodError
//}

メンバを持たないサブクラスも定義可能です。
以下のように、パターンマッチに利用できます。

//emlist[例][ruby]{
class HTTPFetcher
R
esponse = Data.define(:body)
N...
...url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body

in HTTPFetcher::NotFound
:NotFound
end
end

p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}

@param arg...

Data.define(*args) {|subclass| block } -> Class (131.0)

Data クラスに新しいサブクラスを作って、それを返します。

...
Data
クラスに新しいサブクラスを作って、それを返します。

サブクラスでは値オブジェクトのメンバに対するアクセスメソッドが定義されています。

//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # =>...
...Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
fred.age = 6 # => NoMethodError
//}

メンバを持たないサブクラスも定義可能です。
以下のように、パターンマッチに利用できます。

//emlist[例][ruby]{
class HTTPFetcher
R
esponse = Data.define(:body)
N...
...url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body

in HTTPFetcher::NotFound
:NotFound
end
end

p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}

@param arg...