<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stanley W on Medium]]></title>
        <description><![CDATA[Stories by Stanley W on Medium]]></description>
        <link>https://medium.com/@stanley.wongszeyuen?source=rss-060521b61b5e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Stanley W on Medium</title>
            <link>https://medium.com/@stanley.wongszeyuen?source=rss-060521b61b5e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:47:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stanley.wongszeyuen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Purpose of Learning In the Age of AI]]></title>
            <link>https://medium.com/@stanley.wongszeyuen/the-purpose-of-learning-in-the-age-of-ai-24d719e9dbf1?source=rss-060521b61b5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/24d719e9dbf1</guid>
            <dc:creator><![CDATA[Stanley W]]></dc:creator>
            <pubDate>Mon, 02 Nov 2026 11:35:35 GMT</pubDate>
            <atom:updated>2026-11-02T11:35:35.028Z</atom:updated>
            <content:encoded><![CDATA[<p>LLMs have gotten quite astonishing good in writing, problem solving, and a long list of other things. If you have used it in your learning, you may feel like there’s no point in doing it anymore. If LLMs can immediately solve questions you get stuck on for hours, then why not just use it? Why do arithmetics if we have calculators?</p><p>Some people get defensive (which is not unreasonable) at this point and are quick to respond to this problem. But they tend to feel quite lacking. Some will point out a case of failure caused by LLM and asserts that it doesn’t work. But with the experience of solving many quite complicated problems with LLM and using it to code, this simply doesn’t hold up. Not even many human can produce work at that level.</p><p>Instead of blocking our thinking with defensive answers, we need to get back to the starting point.</p><p>The reason we learn is because we want to be capable of doing something. We are not supposed to just learn and then make up a reason why we should do it, even though this may be what’s encouraged by the society.</p><p>Learning is mostly a means to an end. Yes, there are people who learn just for the fun. But in that case we can regard it as a form of entertainment (which becomes a reason of doing on its own). For all other cases, we learn because we want to be able to do something. I learn to code because I want to make software. Someone else learn to write because they want to write well.</p><p>So the question we should ask is: what do you want to do? Can you do it without actually learning anything yourself? If not. Then you have good reasons to learn.</p><p>For many even modestly ambitious project, it is not true yet. No matter how advanced AI becomes there will likely still be things we need to learn.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24d719e9dbf1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Ruby On Rails For AI-Assisted Coders (2): Rails Models]]></title>
            <link>https://medium.com/@stanley.wongszeyuen/an-introduction-to-ruby-on-rails-for-ai-assisted-coders-2-rails-models-df392e187f7f?source=rss-060521b61b5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/df392e187f7f</guid>
            <dc:creator><![CDATA[Stanley W]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 04:23:48 GMT</pubDate>
            <atom:updated>2026-10-22T04:23:48.860Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating A Model</h3><p>A rails model typically corresponds to a database table.</p><pre># app/models/user.rb<br>class User &lt; ApplicationRecord # corresponds to `users` table in the DB<br>  <br>end</pre><p>The database schema lives in the schema.rb, not in the model file. It is modified using migration:</p><pre># creates the users table <br>class CreateUsers &lt; ActiveRecord::Migration[7.1]<br>   def change<br>   create_table :users do |t|<br>   t.string :name, null: false<br>   t.string :email, null: false<br>   t.integer :age<br>   t.timestamps<br>   end<br>   add_index :users, :email, unique: true<br>   end<br>end</pre><p>You can one shot all the above with this prompt:</p><blockquote>Generate a User model and create the corresponding migration.</blockquote><blockquote>User should have a name (string), an email (string), and an age (int).</blockquote><blockquote>Run the migration after finished.</blockquote><h3><strong>Adding Validations</strong></h3><p>You may want to use validations if you want to prevent invalid instances from saving</p><pre>class User &lt; ApplicationRecord <br><br>  ...<br><br>  validates :email, presence: true<br>  validates :age, numericality: { greater_than_or_equal_to: 0 }<br><br>end</pre><p>A simple prompt works here:</p><blockquote>Add validations to the User model. The age should be a number greater than 0. The email must be present.</blockquote><h3>Adding Associations</h3><p>Associations express relationships between models.</p><pre>class User &lt; ApplicationRecord<br><br>  ...<br><br>  has_many :posts, dependent: :destroy<br>  has_one  :profile, dependent: :destroy<br>  has_many :comments, through: :posts<br><br>end</pre><p>With the setup above, you can do all the following (and much more) without writing the methods yourself. It also saves a lot of SQL.</p><pre>user.posts<br>user.posts.find(id)<br>user.posts &lt;&lt; post # append a post<br>user.posts.where(...) <br>user.posts.destroy_all   <br><br>post.user                  <br>post.user = some_user      <br>post.create_comment(...)   # create a new comment and add it to the post</pre><p>Of course, the database schema has to be setup correctly for these to work. The foreign keys need to be in place. But you don’t need to worry about it.</p><p>A single prompt will take care of both of these:</p><blockquote>Create a Post model. A post should have a title (string) and a body (text). User can have one or more posts. A post can only belong to one user.</blockquote><blockquote>Set up the migrations need and run it.</blockquote><h3>Callbacks</h3><p>Callbacks are lifecycle hooks that allows you to call a method</p><pre>class User &lt; ApplicationRecord<br>  after_save :send_welcome_email  <br><br><br>  def send_welcome_email<br>     ....<br>  end<br>end</pre><p>You also have other callbacks like before_save, after_validation etc.</p><blockquote>Add a callback to call this method every time before [model] is saved</blockquote><blockquote>Add a callback to call this method after [model] is validated</blockquote><h3>Methods</h3><p>You can define methods for the model. There is no need to pass self or the column names. Just use it.</p><pre><br>class User &lt; ApplicationRecord <br>   # assumes there is a suspicious column<br><br>   def set_default_suspicious_value<br>      suspicious = 10<br>   end<br><br>   def is_suspicious?<br>      suspicious &gt; 50   # evalutes to true or false<br>   end <br>    <br>    ...<br><br>end</pre><p>There is also no need for a return keyword. Just put the expression you want to return in the end.</p><p>It is very important that you name the methods well. Good Ruby should read like English.</p><h3>Concerns</h3><p>A concern is a code organization tool. It allows you to move code into separate modules so that you don’t end up with enormous model files.</p><p>Below: the code that concerns checking suspicious users are moved to a concern.</p><pre>class User &lt; ApplicationRecord<br>  include User::Suspicious <br>end</pre><pre>module User::Suspicious<br>  extend ActiveSupport::Concern<br><br>   def set_default_suspicious_value<br>      suspicious = 10<br>   end<br><br>   def is_suspicious?<br>      suspicious &gt; 50   # evalutes to true or false<br>   end<br><br>end</pre><blockquote>Extract code related to … into a concern and use it in this model</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df392e187f7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Ruby On Rails For AI-Assisted Coders (1): Overview of Rails]]></title>
            <link>https://medium.com/@stanley.wongszeyuen/an-introduction-to-ruby-on-rails-for-ai-assisted-coders-1-rails-overvoiew-69a642a84c53?source=rss-060521b61b5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/69a642a84c53</guid>
            <dc:creator><![CDATA[Stanley W]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 03:05:03 GMT</pubDate>
            <atom:updated>2026-10-22T03:08:18.055Z</atom:updated>
            <content:encoded><![CDATA[<p>This series of posts is for developers who are going to do AI-assisted development using the Rails framework.</p><p>This first part will give an overview of Rails so that you have the mental model needed to prompt correctly. There is no need to remember the precise code details.</p><h3>What Is Rails?</h3><p>Rails is a full-stack web framework. It handles everything from the frontend to the backend. It also has a lot of magic that saves us from configuring everything manually.</p><p>Rails uses a Model-View-Controller (MVC) architecture.</p><h3>The MVC Architecture</h3><h4>Models</h4><p>Models hold data and business logic. A User model is used to work with the User table in the databse.</p><pre># models/user.rb<br>class User &lt; ApplicationRecord<br>  has_many: chats<br><br># Declares a one-to-many association: this user can own many Chat records.<br># Methods<br><br><br>  def full_name<br>    <br>    &quot;#{first_name} #{last_name}&quot; <br>    # we can access the DB columns of the User table without passing parameters to the method<br>    # this method concancates the values to return a full name by doing user.full_name<br>  end<br>end</pre><p>The corresponding database may look like this. It can be modified via migrations:</p><pre># schema.rb<br>create_table &quot;users&quot;, force: :cascade do |t|<br>  t.string   &quot;first_name&quot;<br>  t.string   &quot;last_name&quot;<br>  t.string   &quot;email&quot;,      null: false<br>  t.string   &quot;role&quot;,       default: &quot;member&quot;<br>  t.datetime &quot;created_at&quot;, null: false<br>  t.datetime &quot;updated_at&quot;, null: false<br>  t.index [&quot;email&quot;], name: &quot;index_users_on_email&quot;, unique: true<br>end</pre><h4>Views</h4><p>Views display the UI. The only thing new here is the embedded Ruby which allows you to retrieve data and have a bit of logic</p><pre># views/users/show.html.erb<br>&lt;h1&gt; User Name &lt;/h1&gt;<br>      &lt;%= user.full_name %&gt;<br>&lt;/ul&gt;<br></pre><p>There are various ways to make the views more interactive, which we will introduce in another post.</p><h4>Controllers</h4><p>We have routes use like any web app. The convenient syntax allows us to not worry much about it with just one line.</p><pre># routes.rb<br>resources :users # This single line define all the routes below<br><br># Verb    /Path          -&gt; Controller#Action : Purpose<br># GET    /users          -&gt; users#index    : List all users<br># GET    /users/new      -&gt; users#new      : show &quot;new user&quot; form<br># POST   /users          -&gt; users#create   : save a new user<br># GET    /users/:id      -&gt; users#show     : show one user<br># GET    /users/:id/edit -&gt; users#edit     : show &quot;edit&quot; form<br># PATCH/PUT /users/:id   -&gt; users#update   : save edits to a user<br># DELETE /users/:id      -&gt; users#destroy  : delete a user</pre><p>Controllers map these routes into different views</p><pre># /controllers/user_controller.rb<br>class UsersController &lt; ApplicationController<br>  def index #renders the view: index.html.erb<br>    @users = User.all          <br> end<br><br>  def show  #renders the view: show.html.erb<br>    @user = User.find(params[:id])<br>  end<br>end</pre><h3>The Process</h3><ol><li>Route (routes.rb) matches /users/1 → UsersController#show, params[:id] = &quot;1&quot;</li><li>Controller runs @user = User.find(1)</li><li>Model (User) queries the users table (defined by the schema), returns row #1 as a Ruby object</li><li>View (show.html.erb) renders @user.full_name (a model method) as HTML</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69a642a84c53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Solution to Ruby Classes With Too Many Responsibilities]]></title>
            <link>https://medium.com/@stanley.wongszeyuen/a-solution-to-ruby-classes-with-too-many-responsibilities-fde9abe089e4?source=rss-060521b61b5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fde9abe089e4</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Stanley W]]></dc:creator>
            <pubDate>Fri, 10 Jul 2026 09:46:22 GMT</pubDate>
            <atom:updated>2026-07-10T09:47:57.532Z</atom:updated>
            <content:encoded><![CDATA[<p>A while ago I was adding a stall detection feature to my LLM chat app. There were several places for the logic to go.</p><p>The first place I thought of was the Chat model. Essentially, I want to be able to do chat.is_stalling? which returns a boolean.</p><pre>class Chat<br>...<br><br>  def is_stalling?<br>  ...<br>  end<br>end</pre><p>But clearly, stall detection is not a core functionality of Chat. So stuffing it here is not good organization. What if we package it into a module or a concern?</p><pre>class Chat<br>  include StallDetection<br><br>...<br>end<br><br># In a concern/module<br>module StallDetection<br>  def is_stalling?<br>  ...<br>  end<br>end </pre><p>This looks reasonable in my opinion. However, the module eventually grows as more granular methods for stall detection were added. And we see a problem:</p><pre>module StallDetection<br>  def is_stalling?<br>  ...<br>  end<br><br>  private<br><br>  def punctuation_only_reply?<br>    ...<br>  end <br><br>  def last_n_replies_short(...)?<br>    ...<br>  end<br><br>  def enough_conversation_history?<br>    ...<br>  end<br>  <br><br>  ...<br>end</pre><p>It is very awkward that Chat has these private methods.</p><p>For example, punctuation_only_reply? would probably fit better in the Message model, but it is so peripheral to Message conceptually that I wouldn’t put it there.</p><p>Adding a bunch of granular stall detection methods to Chat directly is conceptually awkward. So where do these behaviors belong? Another class.</p><p>It seems that there is an missing object that we can delegate to.</p><pre>class Chat<br><br>  delegate :is_stalling?, to: :stall_detector<br>  <br>  def stall_detector<br>    @stall_detector ||= StallDetector.new(self)<br>  end<br><br>...<br>end<br><br>class StallDetector<br>  attr_reader :chat<br><br>  def initialize(...)<br>     ...<br>  end<br><br>  def is_stalling?<br>    ...<br>  end<br><br>  private<br><br>  ...<br>  <br><br>end</pre><p>Now Chat does not have a bunch of peripheral methods, and is_stalling? is delegated to an object specialized for it. Note that StallDetector is not an ActiveRecord model, it is a plain ruby class.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fde9abe089e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple Way of Adding Methods to Chat in RubyLLM]]></title>
            <link>https://medium.com/@stanley.wongszeyuen/simple-way-of-adding-methods-to-chat-in-rubyllm-f4e69424b627?source=rss-060521b61b5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4e69424b627</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Stanley W]]></dc:creator>
            <pubDate>Fri, 10 Jul 2026 08:44:53 GMT</pubDate>
            <atom:updated>2026-07-10T08:45:11.637Z</atom:updated>
            <content:encoded><![CDATA[<p>A while ago I wanted to add an .ask_reliably method that automatically retries with different models if something goes wrong. I used a simple approach.</p><p>First create a module with the new functionalities.</p><pre>module ReliableAsker<br><br>  def ask_reliably(*args, **kwargs, &amp;block)<br>    ...<br>  end<br><br>...<br><br>end</pre><p>Then include it in an initializer, e.g. ruby_llm_extensions.rb</p><pre>module RubyLLM<br>  class Chat<br>    include ReliableAsker<br>  end<br>end<br><br># Now you can do <br># chat = RubyLLM.chat<br># chat.ask_reliably(...)<br></pre><p>However, this does not modify the ActiveRecord Chat model, only the RubyLLM::Chat class. You still cannot do Chat.ask_reliably(…).</p><p>To do that, you need to include the module into your AR model too.</p><pre>class Chat &lt; ApplicationRecord<br>  acts_as_chat <br>  include ReliableAsker <br>end<br><br><br># Now you can do <br># Chat.ask_reliably(...)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4e69424b627" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>