<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>matsubi0526</author_name>
  <author_url>https://blog.hatena.ne.jp/matsubi0526/</author_url>
  <blog_title>matsubi0526の日記</blog_title>
  <blog_url>https://matsubi0526.hatenablog.com/</blog_url>
  <categories>
  </categories>
  <description>Rubyで文字列を整数に変換するには String#to_i を使いますよね。 str = &quot;20&quot; p str.to_i #=&gt; 20 では、でたらめな文字列に対して String#to_i を用いるとどうなるかというと、 str = &quot;hoge&quot; p str.to_i #=&gt; 0 なんと0が返ってくるのです。これはRubyのマニュアルを見ると書いてありますが、 文字列を 10 進数表現された整数であると解釈して、整数に変換する とあります。整数に変換できない文字列に対して、もし例外を発生させるには、Kernel.#Integer を使えばよいみたいです。 str = &quot;hoge&quot; Inte…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fmatsubi0526.hatenablog.com%2Fentry%2F2025%2F03%2F08%2F105805&quot; title=&quot;RubyにおけるString#to_iの挙動 - matsubi0526の日記&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2025-03-08 10:58:05</published>
  <title>RubyにおけるString#to_iの挙動</title>
  <type>rich</type>
  <url>https://matsubi0526.hatenablog.com/entry/2025/03/08/105805</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
